-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution56.java
More file actions
37 lines (33 loc) · 887 Bytes
/
Solution56.java
File metadata and controls
37 lines (33 loc) · 887 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
33
34
35
36
37
package com.usher.algorithm.offer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* @Author: Usher
* @Description:
*/
public class Solution56 {
//num1,num2分别为长度为1的数组。传出参数
//将num1[0],num2[0]设置为返回结果
public void FindNumsAppearOnce(int [] array,int num1[] , int num2[]) {
Map<Integer,Integer> map = new HashMap<>();
for (int v : array){
if (map.containsKey(v)){
int tmp = map.get(v);
map.put(v,tmp+1);
}
else
map.put(v,1);
}
int[] tmp = new int[2];
int i = 0;
for (Integer key : map.keySet()){
if (map.get(key) == 1){
tmp[i++] = key;
}
}
num1[0] = tmp[0];
num2[0] = tmp[1];
}
}