We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e0238c7 commit 7c73299Copy full SHA for 7c73299
Easy/717.1-bit and 2-bit Characters.playground/Contents.swift
@@ -26,15 +26,16 @@
26
*/
27
class Solution {
28
func isOneBitCharacter(_ bits: [Int]) -> Bool {
29
+ if bits.last != 0 { return false }
30
var result = [Int]()
- for (i, c) in bits.enumerated() {
31
- if c == 0 && i != bits.count - 1 {
32
- result.removeAll()
33
- } else {
34
- result.append(c)
+ var index = bits.count - 1
+ while index >= 0 {
+ if index < bits.count - 1 && bits[index] == 0 {
+ break
35
}
36
+ result.append(bits[index])
37
+ index -= 1
38
- if result.last != 0 { return false }
39
return (result.count - 1) % 2 == 0
40
41
0 commit comments