Created
July 31, 2020 15:14
-
-
Save oxlb/8097a179a98222bdf924877e9dac83fe to your computer and use it in GitHub Desktop.
SoldierRank Programming Test
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