Given an array of ints, we'll say that a triple is a value appearing 3 times in a row in the array. Return true if the array does not contain any triples.

noTriples([1, 1, 2, 2, 1]) → true
noTriples([1, 1, 2, 2, 2, 1]) → false
noTriples([1, 1, 1, 2, 2, 2, 1]) → false

1
2
3
4
5
6
7
8
public boolean noTriples(int[] nums) {
  boolean triples=true;
  for (int i=0;i<=nums.length;i++){
    if ((i<=nums.length-3) && (nums[i]==nums[i+1]) && (nums[i]==nums[i+2])){
      triples=false;
    } 
  }return triples;
}

Keresés

Ajánló