Go to a company for an interview ~
The problem with technical questions is to give an array of numbers that appear only once in the box.
Here is the method I gave, not the normal algorithm. There is also no consideration for the complexity of controls.
If you are Daniel, please write your algorithm in the reply. Welcome to Interactive
public static void Main (string[] args) { int array[]={1,3,5,7,9,1,3,5,7}; int length=array.length; StringBuilder sb= new StringBuilder (); for (int i=0;i<length;i++) { sb.append (array[i]); } for (int i=0;i<length;i++) { int firstposition=sb.indexof (array[i]+ ""); int Endposition=sb.lastindexof (array[i]+ ""); if (firstposition==endposition) System.out.println ("occurs once:" +array[i]);} }
Bug raised for 1 floor
I make changes such as the following,
<span style= "Font-size:18px;color: #000000;" >public void Find () { int array[]={11,13,55,77,99,21,13,55,77}; int length=array.length; StringBuilder sb= new StringBuilder (); for (int i=0;i<length;i++) { sb.append (array[i]+ "s"); } for (int i=0;i<length;i++) { int firstposition=sb.indexof (array[i]+ "s"); int Endposition=sb.lastindexof (array[i]+ "s"); if (firstposition==endposition) System.out.println ("occurs once:" +array[i]); else System.out.println ("appears multiple times:" +array[i]);} } </span>
Pick the object that appears only once from the array