更新 Solution.java

master
wangsiyuan 2023-09-12 16:24:57 +08:00
parent 64af01a85d
commit d38af5164a
1 changed files with 20 additions and 4 deletions

View File

@ -132,6 +132,12 @@ public class Solution {
// return ""; // return "";
// } // }
/**
*
* ""
* @param strs
* @return
*/
public static String longestCommonPrefix(String[] strs) { public static String longestCommonPrefix(String[] strs) {
if (strs == null || strs.length == 0) { if (strs == null || strs.length == 0) {
return ""; return "";
@ -148,9 +154,11 @@ public class Solution {
} }
return strs[0]; return strs[0];
} }
//给你一个数组 nums 和一个值 val你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度。 /**
//不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改输入数组。 nums val val
//元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。 使使 O(1)
*/
public static int removeElement(int[] nums, int val) { public static int removeElement(int[] nums, int val) {
int i = 0; int i = 0;
for (int j = 0; j < nums.length; j++) { for (int j = 0; j < nums.length; j++) {
@ -161,6 +169,14 @@ public class Solution {
} }
return i; return i;
} }
/**
* nums 使
* nums
*/
public static int removeDuplicates(int[] nums) {
int i = 0;
int[] newNums = new int[nums.length];
Map<Integer,Integer> duplicates = new HashMap<>();
} }
}