Optimal Java Solution (FEWEST ITERATIONS)


  • 0
    G
    class Solution {
       public boolean isOneBitCharacter(int[] bits) {
           int count = 0;
           for (int i = bits.length-2; i > -1; i--) {
               if (bits[i] == 1) {
                   count++;
               } else {
                   break;
               }
           }
           return (count & 1) == 0;
       }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.