package leetcode;

/**
 * https://leetcode.com/problems/utf-8-validation/
 */
public class Problem393 {
    public boolean validUtf8(int[] data) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem393 prob = new Problem393();
        System.out.println(prob.validUtf8(new int[]{197, 130, 1})); // true
        System.out.println(prob.validUtf8(new int[]{235, 140, 4})); // false
    }
}

@@ -152,35 +152,922 @@
     
-// TODO%0A        return fals
+int i = 0;%0A        int count = 0;%0A        while (i %3C data.length) %7B%0A            int d = data%5Bi%5D;%0A            if (count %3E 0) %7B%0A                if ((d & 0b10000000) == 0b10000000) %7B%0A                    count--;%0A                %7D else %7B%0A                    return false;%0A                %7D%0A            %7D else %7B%0A                if ((d & 0b11110000) == 0b11110000) %7B // 4 bytes%0A                    count = 3;%0A                %7D else if ((d & 0b11100000) == 0b11100000) %7B // 3 bytes%0A                    count = 2;%0A                %7D else if ((d & 0b11000000) == 0b11000000) %7B // 2 bytes%0A                    count = 1;%0A                %7D else %7B // 1 byte%0A                    if (d %3E 0b1111111) %7B%0A                        return false;%0A                    %7D%0A                    count = 0;%0A                %7D%0A            %7D%0A            i++;%0A        %7D%0A        if (count %3E 0) %7B%0A            return false;%0A        %7D%0A        return tru
 e;%0A 
@@ -1314,16 +1314,222 @@
 / false%0A
+        System.out.println(prob.validUtf8(new int%5B%5D%7B127%7D)); // true%0A        System.out.println(prob.validUtf8(new int%5B%5D%7B255%7D)); // false%0A        System.out.println(prob.validUtf8(new int%5B%5D%7B145%7D)); // false%0A
     %7D%0A%7D%0A

Solve problem 393