Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
30 lines (28 loc) · 805 Bytes

File metadata and controls

30 lines (28 loc) · 805 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import java.util.HashMap;
import java.util.Map;
/**
* Created by LX on 3/6/15.
*/
public class MajorityElem {
public int isValid(int[] num) {
if(num.length == 1) return num[0];
HashMap<Integer,Integer> maps = new HashMap<Integer, Integer>() ;
for(int i=0;i<num.length;i++){
Integer n = maps.get(num[i]);
if(n == null){
System.out.println("here");
maps.put(num[i],1);
} else {
System.out.println("x");
maps.put(num[i],n+1);
if(n+1 >= num.length/2) return num[i];
};
}
return 0;
}
public static void main(String args[]){
MajorityElem me = new MajorityElem();
int[] n = {2,2};
me.isValid(n);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.