package pep.Day82;
public class UTF8_Encoding {
public static void main(String[] args) {
int[] arr = {197, 1};
for (int i : arr) {
System.out.println(Integer.toBinaryString(i));
}
System.out.println(solution(arr));
}
private static boolean solution(int[] arr) {
int byteToBeChecked = 0;
for (int i : arr) {
// pehle byte check krne ke lea
if (byteToBeChecked == 0) {
if (i >> 7 == 0b0)
byteToBeChecked = 0;
else if (i >> 5 == 0b110)
byteToBeChecked = 1;
else if (i >> 4 == 0b1110)
byteToBeChecked = 2;
else if (i >> 3 == 0b11110)
byteToBeChecked = 3;
} else {
// agr byteToBeChecked= 1,2,3 to baki sab remaining byte 10 se start hogi
if (i >> 6 != 0b10)
return false;
byteToBeChecked--;
}
}
if (byteToBeChecked == 0)
return true;
return false;
}
}
Monday, May 23, 2022
Utf - 8 Encoding
Subscribe to:
Post Comments (Atom)
Diagonal Traversal
eg. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Output: 1 6 11 16 2 7 12 3 8 4 Approach:...
-
O(1) < O(log n) < O(n) < O(n log n) < O(n ^ 2) ..... < O(2 ^ n) < O(n!) Try to keep TC till O(n ^ 2) ====================...
-
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/ Given the sorted rotated array nums of unique elements, retu...
-
https://leetcode.com/problems/koko-eating-bananas/description/ Piles: 📦 📦 📦 📦 → 4 piles Hours: ⏰ ⏰ ⏰ ⏰ ⏰ ⏰ → 6 h...




No comments:
Post a Comment