Skip to content

Commit e7d20f2

Browse files
committed
Added 4 solutions
1 parent 785c080 commit e7d20f2

4 files changed

Lines changed: 82 additions & 0 deletions

File tree

Easy/Assign Cookies.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int findContentChildren(int[] g, int[] s) {
3+
Arrays.sort(g);
4+
Arrays.sort(s);
5+
int count = 0;
6+
for (int i=0;i<g.length;i++) {
7+
for (int j=0;j<s.length;j++) {
8+
if (g[i] <= s[j]) {
9+
s[j] = 0;
10+
count++;
11+
break;
12+
}
13+
}
14+
}
15+
return count;
16+
}
17+
}

Easy/Climbing Stairs.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int climbStairs(int n) {
3+
if (n == 1) return 1;
4+
if (n == 2) return 2;
5+
6+
int oneStep = 2;
7+
int twoStep = 1;
8+
int all = 0;
9+
10+
for (int i=2;i<n;i++) {
11+
all = oneStep + twoStep;
12+
twoStep = oneStep;
13+
oneStep = all;
14+
}
15+
16+
return all;
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int findLengthOfLCIS(int[] nums) {
3+
if (nums.length == 0) return 0;
4+
if (nums.length == 1) return 1;
5+
6+
int c = 1;
7+
int maxL = 1;
8+
for (int i=1;i<nums.length;i++) {
9+
if (nums[i-1] < nums[i]) {
10+
c++;
11+
}
12+
else {
13+
maxL = Math.max(c,maxL);
14+
c = 1;
15+
}
16+
}
17+
return Math.max(c,maxL);
18+
}
19+
}

Easy/Longest Palindrome.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public int longestPalindrome(String s) {
3+
int[] count = new int[52];
4+
5+
for (int i=0;i<s.length();i++) {
6+
int ind = ((int) s.charAt(i));
7+
if (ind >= 97) {
8+
ind -= 97;
9+
}
10+
else {
11+
ind = ind + 26 - 65;
12+
}
13+
count[ind]++;
14+
}
15+
16+
int l = 0;
17+
for (int i=0;i<52;i++) {
18+
if (count[i]%2 == 0) {
19+
l += count[i];
20+
}
21+
else {
22+
l += count[i]-1;
23+
}
24+
}
25+
26+
return s.length() > l ? l+1 : l;
27+
}
28+
}

0 commit comments

Comments
 (0)