You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 124 Binary Tree Maximum Path Sum.js
+18-1Lines changed: 18 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,16 @@
1
+
// Given a binary tree, find the maximum path sum.
2
+
3
+
// For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path does not need to go through the root.
// Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.
2
+
3
+
// For example,
4
+
// Given nums = [1,3,-1,-3,5,3,6,7], and k = 3.
5
+
6
+
// Window position Max
7
+
// --------------- -----
8
+
// [1 3 -1] -3 5 3 6 7 3
9
+
// 1 [3 -1 -3] 5 3 6 7 3
10
+
// 1 3 [-1 -3 5] 3 6 7 5
11
+
// 1 3 -1 [-3 5 3] 6 7 5
12
+
// 1 3 -1 -3 [5 3 6] 7 6
13
+
// 1 3 -1 -3 5 [3 6 7] 7
14
+
// Therefore, return the max sliding window as [3,3,5,5,6,7].
15
+
16
+
/**
17
+
* @param {number[]} nums
18
+
* @param {number} k
19
+
* @return {number[]}
20
+
*/
21
+
varmaxSlidingWindow=function(nums,k){
22
+
varresult=[],
23
+
linkedListWithTwoEndsOps=[],
24
+
len=nums.length,
25
+
i;
26
+
27
+
if(k>len||k===0){
28
+
returnresult;
29
+
}
30
+
31
+
for(i=0;i<len;i++){
32
+
// Remove anything that is less than the current value
33
+
// so linkedListWithTwoEndsOps maintains values greater than the curret value
0 commit comments