Skip to content

Commit 15f114a

Browse files
authored
Add spaces after control flow statements.
1 parent f71f609 commit 15f114a

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

javascript/0606-construct-string-from-binary-tree.js

+16-15
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414
* @return {string}
1515
*/
1616
var tree2str = function(root) {
17+
return dfs(root, []).join("");
18+
};
1719

18-
let str = "";
19-
const dfs = (node) => {
20-
if(!node) return;
21-
str += node.val;
22-
if(node.right || node.left) str += "(";
23-
dfs(node.left);
24-
if(node.right || node.left) str += ")";
20+
const dfs = (node, strArr) => {
21+
if (!node) return;
2522

26-
// right tree
27-
if(node.right) str += "(";
28-
dfs(node.right);
29-
if(node.right) str += ")";
30-
}
23+
strArr.push(node.val);
3124

32-
dfs(root);
33-
return str;
34-
};
25+
if (node.right || node.left) strArr.push("(");
26+
dfs(node.left, strArr);
27+
if (node.right || node.left) strArr.push(")");
28+
29+
// right tree
30+
if (node.right) strArr.push("(");
31+
dfs(node.right, strArr);
32+
if (node.right) strArr.push(")");
33+
34+
return strArr;
35+
}

0 commit comments

Comments
 (0)