diff --git a/problems/0112.路径总和.md b/problems/0112.路径总和.md index d50f23f9..cb9d343f 100644 --- a/problems/0112.路径总和.md +++ b/problems/0112.路径总和.md @@ -33,7 +33,7 @@ * 112.路径总和 * 113.路径总和ii -这道题我们要遍历从根节点到叶子节点的的路径看看总和是不是目标和。 +这道题我们要遍历从根节点到叶子节点的路径看看总和是不是目标和。 ### 递归 @@ -167,7 +167,7 @@ public: }; ``` -**是不是发现精简之后的代码,已经完全看不出分析的过程了,所以我们要把题目分析清楚之后,在追求代码精简。** 这一点我已经强调很多次了! +**是不是发现精简之后的代码,已经完全看不出分析的过程了,所以我们要把题目分析清楚之后,再追求代码精简。** 这一点我已经强调很多次了! ### 迭代 @@ -316,13 +316,13 @@ class solution { } if (root.left != null) { boolean left = haspathsum(root.left, targetsum); - if (left) {// 已经找到 + if (left) { // 已经找到 return true; } } if (root.right != null) { boolean right = haspathsum(root.right, targetsum); - if (right) {// 已经找到 + if (right) { // 已经找到 return true; } } @@ -348,31 +348,37 @@ class solution { ```java class solution { public boolean haspathsum(treenode root, int targetsum) { - if(root==null)return false; + if(root == null) return false; stack stack1 = new stack<>(); stack stack2 = new stack<>(); - stack1.push(root);stack2.push(root.val); - while(!stack1.isempty()){ + stack1.push(root); + stack2.push(root.val); + while(!stack1.isempty()) { int size = stack1.size(); - for(int i=0;i