-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYitu_Interview1.java
More file actions
32 lines (27 loc) · 847 Bytes
/
Yitu_Interview1.java
File metadata and controls
32 lines (27 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.Map;
import java.util.HashMap;
class Yitu_Interview1 {
public static void main(String args[]) {
int[] A = new int[]{1, 1, 0, 0, 1};
removeElement(A);
}
public static int removeElement(int[] A){
Map<Integer, Integer> posToCount = new HashMap<Integer, Integer> ();
int lastElem = -1;
for(int i=0; i<A.length; i++){
if(A[i] == lastElem){
posToCount.put(i, posToCount.get(i) + 1);
}else{
posToCount.put(i, 1);
}
lastElem = A[i];
}
Map<Integer, Integer> neigCounts = new HashMap<Integer, Integer>();
for(Map.Entry pair:posToCount.entrySet()){
//if(neigCounts.containsKey(pair.getKey())){
//}
//posToCount.
}
return 0;
}
}