Skip to content

Commit d809d39

Browse files
committed
做了道题
1 parent 7f961ce commit d809d39

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

main.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,51 @@ def isOneBitCharacter(self, bits: List[int]) -> bool:
16551655
return dp[-1][0] == 1 and sum(dp[-1]) == 1
16561656

16571657
def numDecodings(self, s: str) -> int:
1658+
n = len(s)
1659+
1660+
if s[0] == "0":
1661+
return 0
1662+
if n == 1:
1663+
return 1
1664+
1665+
dp = [0] * n
1666+
dp[0] = 1
1667+
if 0 < int(s[0]) < 2 or int(s[0]) == 2 and int(s[1]) < 7:
1668+
dp[1] = 1
1669+
1670+
if s[1] != "0":
1671+
dp[1] += 1
1672+
1673+
1674+
for i in range(2, n):
1675+
if 0<int(s[i-1])<2 or int(s[i-1])==2 and int(s[i]) < 7:
1676+
dp[i] += dp[i-2]
1677+
if s[i] != "0":
1678+
dp[i] += dp[i-1]
1679+
1680+
print(dp)
1681+
return dp[-1]
1682+
1683+
def intersectionSizeTwo(self, intervals: List[List[int]]) -> int:
1684+
intervals.sort(key=lambda x: (x[0], -x[1]))
1685+
ans, n, m = 0, len(intervals), 2
1686+
vals = [[] for _ in range(n)]
1687+
for i in range(n - 1, -1, -1):
1688+
j = intervals[i][0]
1689+
for k in range(len(vals[i]), m):
1690+
ans += 1
1691+
for p in range(i - 1, -1, -1):
1692+
if intervals[p][1] < j:
1693+
break
1694+
vals[p].append(j)
1695+
j += 1
1696+
return ans
1697+
1698+
1699+
1700+
1701+
16581702

16591703

16601704
s = Solution()
1661-
print(s.isOneBitCharacter(bits = [1,1,1,0]))
1705+
print(s.numDecodings("226"))

0 commit comments

Comments
 (0)