<awangdev>229. Majority Element II_1.java
public List<Integer> majorityElement(int[] nums) {
        List<Integer> result = new ArrayList<>();
        if (nums == null || nums.length == 0) {
            return result;
        }
        int valA = 0, valB = 0, countA = 0, countB = 0;
        for (int num : nums) {
            if (num == valA) {
                countA++;
            } else if (num == valB) {
                countB++;
            } else if (countA == 0) {
                valA = num;
                countA++;
            } else if (countB == 0){
                valB = num;
                countB++;
            } else {
                countA--;
                countB--;
            }
        }
        
        countA = 0; 
        countB = 0;
        for (int num : nums) {
            if (num == valA) {
                countA++;
            } else if (num == valB) {
                countB++;
            }
        }
        if (countA > nums.length / 3) result.add(valA);
        if (countB > nums.length / 3) result.add(valB);
        return result;
    }
public List < Integer > var_1 ( int [ ] var_2 ) {
  List < Integer > var_5 = new ArrayList < > ( ) ;
  if ( var_2 == null || var_2 . length == 0 ) {
    return var_5 ;
  }
  int var_9 = 0 , var_10 = 0 , var_11 = 0 , var_12 = 0 ;
  for ( int var_13 : var_2 ) {
    if ( var_13 == var_9 ) {
      var_11 ++ ;
    }
    else if ( var_13 == var_10 ) {
      var_12 ++ ;
    }
    else if ( var_11 == 0 ) {
      var_9 = var_13 ;
      var_11 ++ ;
    }
    else if ( var_12 == 0 ) {
      var_10 = var_13 ;
      var_12 ++ ;
    }
    else {
      var_11 -- ;
      var_12 -- ;
    }
  }
  var_11 = 0 ;
  var_12 = 0 ;
  for ( int var_13 : var_2 ) {
    if ( var_13 == var_9 ) {
      var_11 ++ ;
    }
    else if ( var_13 == var_10 ) {
      var_12 ++ ;
    }
  }
  if ( var_11 > var_2 . length / 3 ) var_5 . add ( var_9 ) ;
  if ( var_12 > var_2 . length / 3 ) var_5 . add ( var_10 ) ;
  return var_5 ;
}
