There is a sequence of characters. each character can be either one-byte character or two-byte character. For the one-byte character, its value fall in [0,127]; for a two-byte character, the value of the first byte must be larger than 127 and the second byte can take any value.
Now you are given you a position along the sequence. It can be a one-byte character, or any one byte of the two-byte character. You are required to return the character right before the position.
The key to the pattern is to scan backwards and find the first Byte with first bit 0. This Byte ensures an end of a character. And then scan forwards...
Think:
HL ->after this pattern, it is a new start for a word
LL ->after this pattern, it is a new start for a word
HH ->cannot determine
LH ->cannot determine
Utf-8:
http://en.wikipedia.org/wiki/Utf8#Description
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment