diff --git a/src/solution/Solution.java b/src/solution/Solution.java index 76dc399..30c9e0a 100644 --- a/src/solution/Solution.java +++ b/src/solution/Solution.java @@ -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; + } }