Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6157edc

Browse files
committed
keep solving 113, 114
1 parentdf1c68a commit6157edc

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

‎Medium/113-pathSumII.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
*@param {TreeNode} root
3+
*@param {number} sum
4+
*@return {number[][]}
5+
*/
6+
varpathSum=function(root,sum){
7+
varresult=[];
8+
varresults=[];
9+
pathSumHelper(root,sum,result,results);
10+
returnresults;
11+
};
12+
13+
varpathSumHelper=function(root,sum,result,results){
14+
if(!root){
15+
return;
16+
}
17+
result.push(root.val);
18+
if(!root.left&&!root.right&&sum===root.val){
19+
results.push(result.slice());
20+
}
21+
pathSumHelper(root.left,sum-root.val,result,results);
22+
pathSumHelper(root.right,sum-root.val,result,results);
23+
result.pop();
24+
};

‎Medium/114-flattenTree.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
*@param {TreeNode} root
3+
*@return {void} Do not return anything, modify root in-place instead.
4+
*/
5+
varflatten=function(root){
6+
if(!root)return;
7+
varoRoot=root;
8+
flatten(root.left);
9+
flatten(root.right);
10+
varoRight=oRoot.right;
11+
oRoot.right=oRoot.left;
12+
oRoot.left=null;
13+
while(oRoot.right)oRoot=oRoot.right;
14+
oRoot.right=oRight;
15+
};

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@
116116
*[98. Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/) -[Solution](./Medium/98-validateBST.js)
117117
*[103. Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/) -[Solution](./Medium/103-BSTZigzagLevelTraversal.js)
118118
*[108. Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/) -[Solution](./Medium/108-convertSortedArraytoBST.js)
119+
*[113. Path Sum II](https://leetcode.com/problems/path-sum-ii/) -[Solution](./Medium/113-pathSumII.js)
120+
*[114. Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list/) -[Solution](./Medium/114-flattenTree.js)
119121
*[116. Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node/) -[Solution](./Medium/116-PopulatingNextRightPointersinEachNode.js)
120122
*[121. Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) -[Solution](./Medium/121-bestTimeToBuySellStock.js)
121123
*[122. Best Time to Buy and Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/) -[Solution](./Medium/122-bestTimeToBuySellStockII.js)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp