leetcode 2689. Extract Kth Character From The Rope Tree - recursion and comments on problem

preview_player
Показать описание
Follow up at my channel @Code-Yao and corresponding playlists.
Рекомендации по теме
Комментарии
Автор

This code is based on the assumption that:
for a node node.len := len(S[node])
it seems that we could not interpret the above assumption
from the problem statement


class Solution:
def getKthCharacter(self, root: Optional[object], k: int) -> str:
while root.len:
length = max(root.left.len, len(root.left.val)) if root.left else 0
if length >= k:
root = root.left
else:
root = root.right
k -= length
return root.val[k - 1]

codeyao
welcome to shbcf.ru