LeetCode - Remove Duplicates from Sorted Array
时间:2015-04-03 11:11:37
收藏:0
阅读:224
删除数组里重复的元素,返回数组的元素个数。可以利用set集合元素不重复的特点来保存。
public class Solution { public int removeDuplicates(int[] A) { java.util.SortedSet<Integer> set = new java.util.TreeSet<>(); for(int i=0; i<A.length; i++) { set.add(A[i]); } int j = 0; for(int i : set) { A[j++] = i; } return set.size(); } }
原文:http://www.cnblogs.com/wxisme/p/4389340.html
评论(0)