393. UTF-8-Validation πŸ”₯

Medium

Problem:

Verify if the input value is a valid UTF-8 string.

Example 1:

Example 2:

https://leetcode.com/problems/utf-8-validation/arrow-up-right

Solution:

  1. first is the first byte. If the first byte starts with 0, it's a 1-byte character. If it starts with 110, it's a 2-byte character. If it starts with 1110, it's a 3-byte character. If it starts with 11110, it's a 4-byte character.

  2. The check() function takes size as a parameter and determines if that many bytes start with 10.

Last updated