Skip to content

Instantly share code, notes, and snippets.

@oxlb
Created July 31, 2020 15:17
Show Gist options
  • Save oxlb/6177452c32463c585753ec39c9249e6a to your computer and use it in GitHub Desktop.
Save oxlb/6177452c32463c585753ec39c9249e6a to your computer and use it in GitHub Desktop.
SoldierRank
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