2
심도있는 검색을위한 간단한 장난감 코드가 있는데 왜 인쇄 후에 %가 표시됩니까?재귀 DFS 뒤에 특수 문자가 인쇄되는 이유는 무엇입니까?
# Definition for a binary tree node
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def dfs(t):
if t==None:
print("",end="")
else:
print(t.val,end="")
dfs(t.left)
dfs(t.right)
t=TreeNode(1)
t.left=TreeNode(2)
t.right=TreeNode(3)
t.left.left=TreeNode(4)
t.left.right=TreeNode(5)
t.right.left=TreeNode(6)
t.right.right=TreeNode(7)
dfs(t)
출력 : 1백24만5천3백67% 쉘 프롬프트의
이것은 @ user2357112가 옳다고 가정하고 (안전 베팅) [예제]를 최소화해야하는 또 다른 이유입니다. 예제를 최소화하는 과정에서 실제로는 의존하지 않는다는 것을 알았을 것입니다 대부분의 코드. – DSM
@DSM 감사합니다! 나는 새로운 사람이고, 묻는 법을 배우려고 노력하고 있습니다. – hxd1011