이진 트리에서 문자열 구성
                                            
                                                
                                                
                                                
                                                
                                                
                                                 2875 단어  leetcodepythonprogramming
                    
문자열과 원래 이진 트리 간의 일대일 매핑 관계에 영향을 주지 않는 모든 빈 괄호 쌍을 생략합니다.
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public String tree2str(TreeNode t) {
        if(t==null)
            return "";
        if(t.left==null && t.right==null)
            return t.val+"";
        if(t.right==null)
            return t.val+"("+tree2str(t.left)+")";
        return t.val+"("+tree2str(t.left)+")("+tree2str(t.right)+")";   
    }
}
Reference
이 문제에 관하여(이진 트리에서 문자열 구성), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/salahelhossiny/construct-string-from-binary-tree-34n6텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)