Skip to content
This repository was archived by the owner on Apr 27, 2025. It is now read-only.

Commit 06f3017

Browse files
authored
Update 91. Decode Ways.md
1 parent 8e6991f commit 06f3017

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

91. Decode Ways.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Explanation: It could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
3131
class Solution {
3232
private var cache = [Int]()
3333
private func numDecodingsForSubString(start: Int, end: Int, c: [Int8]) -> Int {
34-
let index = start * 2 + (end - start)
34+
let index = start * 2 + (end - start) - 1
3535
if cache[index] >= 0 {
3636
return cache[index]
3737
}
@@ -59,7 +59,7 @@ class Solution {
5959
func numDecodings(_ s: String) -> Int {
6060
var c = s.utf8CString.map({ $0 - 48 })
6161
c.removeLast()
62-
cache = [Int].init(repeating: -1, count: c.count * 2 + 2)
62+
cache = [Int].init(repeating: -1, count: c.count * 2)
6363
return numDecodingsForSubString(start: 0, end: 1, c: c) + numDecodingsForSubString(start: 0, end: 2, c: c)
6464
}
6565
}

0 commit comments

Comments
 (0)