File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -337,6 +337,21 @@ func sumOfLeftLeaves(root *TreeNode) int {
337337}
338338```
339339
340+ ** 递归精简版**
341+
342+ ``` go
343+ func sumOfLeftLeaves (root *TreeNode ) int {
344+ if root == nil {
345+ return 0
346+ }
347+ leftValue := 0
348+ if root.Left != nil && root.Left .Left == nil && root.Left .Right == nil {
349+ leftValue = root.Left .Val
350+ }
351+ return leftValue + sumOfLeftLeaves (root.Left ) + sumOfLeftLeaves (root.Right )
352+ }
353+ ```
354+
340355** 迭代法(前序遍历)**
341356
342357``` go
Original file line number Diff line number Diff line change @@ -100,6 +100,18 @@ public:
100100## 其他语言版本
101101
102102### Java:
103+ 排序法
104+ ``` Java
105+ class Solution {
106+ public int [] sortedSquares (int [] nums ) {
107+ for (int i = 0 ; i < nums. length; i++ ) {
108+ nums[i] = nums[i] * nums[i];
109+ }
110+ Arrays . sort(nums);
111+ return nums;
112+ }
113+ }
114+ ```
103115
104116``` Java
105117class Solution {
You can’t perform that action at this time.
0 commit comments