Created
May 5, 2018 02:25
-
-
Save sphilee/56a450a236342d12f5a429f1c17d9b34 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
| function solution(A) { | |
| // write your code in JavaScript (Node.js 8.9.4) | |
| const map = A.reduce((map,v,i)=>{ | |
| map[v] ? map[v].push(i) : map[v] = [i]; | |
| return map; | |
| },{}); | |
| for(let item in map){ | |
| if(map[item].length > A.length/2) return map[item][0]; | |
| } | |
| return -1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment