Created
July 31, 2020 15:17
-
-
Save oxlb/6177452c32463c585753ec39c9249e6a to your computer and use it in GitHub Desktop.
SoldierRank
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
class Solution { | |
public int solution(int[] ranks) { | |
// write your code in Java SE 8 | |
int sum = 0; | |
Set<Integer> soldierRank = new HashSet<Integer>(); | |
for (int i = 0; i< ranks.length; i++) { | |
soldierRank.add(ranks[i]); | |
} | |
for(int k = 0; k < ranks.length; k++){ | |
if(soldierRank.contains(ranks[k]+1)){ | |
sum++; | |
} | |
} | |
return sum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment