Compare commits

..

No commits in common. "27074cb4c61614bda44b64fb5b6d21030aa94d26" and "6c39c4d46270a16d7cfbb82bb54d2bdb148f4f77" have entirely different histories.

2 changed files with 4 additions and 61 deletions

View File

@ -205,12 +205,7 @@ public class Solution {
return true; return true;
} }
/**
*
* @param list1
* @param list2
* @return
*/
public ListNode mergeTwoLists(ListNode list1, ListNode list2) { public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
ListNode dummy = new ListNode(0); ListNode dummy = new ListNode(0);
ListNode current = dummy; ListNode current = dummy;
@ -232,26 +227,11 @@ public class Solution {
return dummy.next; return dummy.next;
} }
/**
* haystack needle haystack needle 0 needle haystack -1
* @param haystack
* @param needle
* @return
*/
public int strStr(String haystack, String needle) { public int strStr(String haystack, String needle) {
if (needle.isEmpty()) return -1; if (needle.isEmpty()) return -1;
return haystack.indexOf(needle); return haystack.indexOf(needle);
} }
/**
*
*
* 使 O(log n)
* @param nums
* @param target
* @return
*/
public int searchInsert(int[] nums, int target) { public int searchInsert(int[] nums, int target) {
if (nums.length == 0) return 0; if (nums.length == 0) return 0;
for (int i = 0; i < nums.length; i++) { for (int i = 0; i < nums.length; i++) {
@ -262,13 +242,6 @@ public class Solution {
return nums.length; return nums.length;
} }
/**
* s
*
*
* @param s
* @return
*/
public int lengthOfLastWord(String s) { public int lengthOfLastWord(String s) {
if (s.isEmpty()) return 0; if (s.isEmpty()) return 0;
for (int i = s.length() - 1; i >= 0; i--) { for (int i = s.length() - 1; i >= 0; i--) {
@ -283,34 +256,4 @@ public class Solution {
} }
return 0; return 0;
} }
/**
*
*
*
*
* 0
* @param digits
* @return
*/
public static int[] plusOne(int[] digits) {
int n = digits.length;
// 从数组的最后一位开始处理进位
for (int i = n - 1; i >= 0; i--) {
if (digits[i] < 9) {
digits[i]++;
return digits;
}
// 如果当前位是9则将其置为0
digits[i] = 0;
}
// 如果所有的数字都是9那么会到这里
// 创建一个新的数组其长度比原数组多1
int[] newNumber = new int[n + 1];
newNumber[0] = 1;
return newNumber;
}
} }

View File

@ -6,9 +6,9 @@ import java.util.stream.Collectors;
public class test { public class test {
public static void main(String[] args) { public static void main(String[] args) {
int[] nums = new int[]{9}; int[] nums = new int[]{1,1,2};
int[] result = Solution.plusOne(nums); int result = Solution.removeDuplicates(nums);
System.out.println(result.toString()); System.out.println(result);
} }
} }