赞
踩
- public class Solution {
- /**
- * @param A: a array of integers
- * @return : return an integer
- */
- public int removeDuplicates(int[] nums) {
- // write your code here
- if(nums == null || nums.length == 0) return 0;
- int reslen = 0;
- int j = reslen;
- int len = nums.length;
- Map<Integer,Integer> times = new HashMap<>();
-
- //int[] times = new int[len]; 有负数的情况
- for(int i = 0 ; i < len; i++){
- int cou = 0;
- if(times.containsKey(nums[i])){
- cou = times.get(nums[i]);
- }else{
- times.put(nums[i],cou);
- }
- if(cou < 2){
- nums[j++] = nums[i];
- // times[nums[i]] += 1;
-
- times.put(nums[i], ++cou);
- } else{
- // times[nums[i]] += 1;
- times.put(nums[i], ++cou);
- }
- }
- reslen = j;
- return reslen;
- }
- }
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。