Compare commits
2 Commits
c72996f342
...
6c39c4d462
| Author | SHA1 | Date |
|---|---|---|
|
|
6c39c4d462 | |
|
|
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class test {
|
||||
public static void main(String[] args) {
|
||||
int[] nums = new int[]{1,2,3,4,4,5,6};
|
||||
boolean canJump = Solution.canJump(nums);
|
||||
System.out.println(canJump);
|
||||
int[] nums = new int[]{1,1,2};
|
||||
int result = Solution.removeDuplicates(nums);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue