Update Solution.java
parent
c72996f342
commit
b75d236fbb
|
|
@ -226,4 +226,34 @@ public class Solution {
|
|||
}
|
||||
return dummy.next;
|
||||
}
|
||||
|
||||
public int strStr(String haystack, String needle) {
|
||||
if (needle.isEmpty()) return -1;
|
||||
return haystack.indexOf(needle);
|
||||
}
|
||||
|
||||
public int searchInsert(int[] nums, int target) {
|
||||
if (nums.length == 0) return 0;
|
||||
for (int i = 0; i < nums.length; i++) {
|
||||
if (nums[i] >= target) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return nums.length;
|
||||
}
|
||||
|
||||
public int lengthOfLastWord(String s) {
|
||||
if (s.isEmpty()) return 0;
|
||||
for (int i = s.length() - 1; i >= 0; i--) {
|
||||
if (s.charAt(i) != ' ') {
|
||||
int count = 0;
|
||||
while (i >= 0 && s.charAt(i) != ' ') {
|
||||
count++;
|
||||
i--;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue