Skip to content

Commit a62468e

Browse files
authored
Merge pull request #1257 from cn920423/master
311-Week 08
2 parents 7c99f92 + 7abd395 commit a62468e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Solution {
2+
public int lengthOfLIS(int[] nums) {
3+
int[] dp = new int[nums.length];
4+
int len = 0;
5+
for (int num : nums) {
6+
int i = Arrays.binarySearch(dp, 0, len, num);
7+
if (i < 0) {
8+
i = -(i + 1);
9+
}
10+
dp[i] = num;
11+
if (i == len) {
12+
len++;
13+
}
14+
}
15+
return len;
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public int lengthOfLastWord(String s) {
3+
int end = s.length() - 1;
4+
while(end >= 0 && s.charAt(end) == ' ') end--;
5+
if(end < 0) return 0;
6+
int start = end;
7+
while(start >= 0 && s.charAt(start) != ' ') start--;
8+
return end - start;
9+
}
10+
}

0 commit comments

Comments
 (0)