ขนาดวิดีโอ: 1280 X 720853 X 480640 X 360
แสดงแผงควบคุมโปรแกรมเล่น
เล่นอัตโนมัติ
เล่นใหม่
#TC=O(high)#SC=O(high)class Solution: def countGoodStrings(self, low: int, high: int, zero: int, one: int) -> int: MOD=7+(10**9) dp=[0 for _ in range(high+1)] #dp[i]=no of good strings of len=i ans=0 dp[zero]+=1 dp[one]+=1 #print(dp) for i in range(min(zero,one),high+1): if(i-zero in range(high+1)): dp[i]+=(dp[i-zero])%MOD if(i-one in range(high)): dp[i]+=(dp[i-one])%MOD dp[i]=dp[i]%MOD if(i in range(low,high+1)): ans+=dp[i] #print(dp) return ans%MOD# 0# 11#example -2 tracing# l=1# 0# l=2# 11, 00# l=3# 011, 110, 000
Hindi Explanation: th-cam.com/video/1gBkuf7E-6Q/w-d-xo.html
#TC=O(high)
#SC=O(high)
class Solution:
def countGoodStrings(self, low: int, high: int, zero: int, one: int) -> int:
MOD=7+(10**9)
dp=[0 for _ in range(high+1)] #dp[i]=no of good strings of len=i
ans=0
dp[zero]+=1
dp[one]+=1
#print(dp)
for i in range(min(zero,one),high+1):
if(i-zero in range(high+1)):
dp[i]+=(dp[i-zero])%MOD
if(i-one in range(high)):
dp[i]+=(dp[i-one])%MOD
dp[i]=dp[i]%MOD
if(i in range(low,high+1)):
ans+=dp[i]
#print(dp)
return ans%MOD
# 0
# 11
#example -2 tracing
# l=1
# 0
# l=2
# 11, 00
# l=3
# 011, 110, 000
Hindi Explanation: th-cam.com/video/1gBkuf7E-6Q/w-d-xo.html