Remove duplicates from integer array

前端 未结 23 2407
执念已碎
执念已碎 2020-12-01 18:52

I having a problem with coding this:

Write a static method named removeDuplicates that takes as input an array of integers and returns as a result a new

23条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 19:32

    What you have to do is , you have to check for each element in second array whether previous element is already present or not.

    You can use better approach Use HashSet and return set.

    public static Set removeDuplicates(int []s){
      Set set = new HashSet();       
       for(int i=0;i

    If you need int Array than take a look of this java-hashsetinteger-to-int-array link.

提交回复
热议问题