Created
October 21, 2016 07:51
-
-
Save kninami/5d92ea3d426cf6bf5764490d394c83e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.HashMap; | |
| import java.util.Iterator; | |
| import java.util.Map.Entry; | |
| class Solution { | |
| public int solution(int[] A) { | |
| int result=0; | |
| HashMap<Integer , Integer> map = new HashMap<Integer , Integer>(); | |
| for(int i=0;i<A.length;i++){ | |
| int key = A[i]; | |
| if(map.containsKey(key)){ | |
| map.put(key,map.get(key) + 1); | |
| }else{ | |
| map.put(key,1); | |
| } | |
| } | |
| Iterator iterator = map.entrySet().iterator(); | |
| while (iterator.hasNext()) { | |
| Entry entry = (Entry)iterator.next(); | |
| if(((int)entry.getValue()%2)==1){ | |
| result = (int)entry.getKey(); | |
| } | |
| } | |
| return result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment