class Solution:
def findKthBit(self, n: int, k: int) -> str:
dp = ["0"]
def rev(val):
return val[::-1]
def inv(val):
res = ""
for i in val:
if i == "1":
res +="0"
elif i == "0":
res += "1"
return res
for i in range(n-1):
s = dp[-1] + "1"
s += rev(inv(dp[-1]))
dp.append(s)
#print(dp)
return dp[n-1][k-1]top of page
To see this working, head to your live site.
LeetCode 1545 - Find Kth Bit in Nth Binary String
LeetCode 1545 - Find Kth Bit in Nth Binary String
0 comments
Comments (0)
Commenting on this post isn't available anymore. Contact the site owner for more info.
Forum: Forum
bottom of page