Compare commits
No commits in common. "64af01a85d388564700283612e6a25e17b87b20d" and "ded5c3051c0bb4d80805f50a7d52fdb3106520b5" have entirely different histories.
64af01a85d
...
ded5c3051c
|
|
@ -148,19 +148,4 @@ public class Solution {
|
||||||
}
|
}
|
||||||
return strs[0];
|
return strs[0];
|
||||||
}
|
}
|
||||||
//给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度。
|
|
||||||
//不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改输入数组。
|
|
||||||
//元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。
|
|
||||||
public static int removeElement(int[] nums, int val) {
|
|
||||||
int i = 0;
|
|
||||||
for (int j = 0; j < nums.length; j++) {
|
|
||||||
if (nums[j] != val) {
|
|
||||||
nums[i] = nums[j];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,22 @@ 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[]{3,2,2,3,1,2};
|
|
||||||
int[] nums1 = new int[]{1,2,3,0,0,0};
|
int[] nums1 = new int[]{1,2,3,0,0,0};
|
||||||
int length = Solution.removeElement(nums,3);
|
// int m = 3;
|
||||||
System.out.println(nums);
|
// int[] nums2 = new int[]{2,5,6};
|
||||||
System.out.println(length);
|
// int n = 3;
|
||||||
|
// int[] nums1 = new int[]{1};
|
||||||
|
// int m = 1;
|
||||||
|
// int[] nums2 = new int[]{};
|
||||||
|
// int n = 0;
|
||||||
|
// Solution.merge(nums1,m,nums2,n);
|
||||||
|
// String[] strs = new String[]{"flower","flow","flight"};
|
||||||
|
// String[] strs = new String[]{"flower","flower","flower","flower"};
|
||||||
|
// String result = Solution.longestCommonPrefix(strs);
|
||||||
|
// System.out.println(result);
|
||||||
|
// int m = Solution.majorityElement(nums1);
|
||||||
|
// System.out.println(m);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue