File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 24
24
43|[ Multiply Strings] ( ./0043-multiply-strings.js ) |Medium|
25
25
49|[ Group Anagrams] ( ./0049-group-anagrams.js ) |Medium|
26
26
50|[ Pow(x, n)] ( ./0050-powx-n.js ) |Medium|
27
+ 53|[ Maximum Subarray] ( ./0053-maximum-subarray.js ) |Easy|
27
28
54|[ Spiral Matrix] ( ./0054-spiral-matrix.js ) |Medium|
28
29
58|[ Length of Last Word] ( ./0058-length-of-last-word.js ) |Easy|
29
30
66|[ Plus One] ( ./0066-plus-one.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 53. Maximum Subarray
3
+ * https://leetcode.com/problems/maximum-subarray/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given an integer array `nums`, find the contiguous subarray (containing at
7
+ * least one number) which has the largest sum and return its sum.
8
+ *
9
+ * A subarray is a contiguous part of an array.
10
+ */
11
+
12
+ /**
13
+ * @param {number[] } nums
14
+ * @return {number }
15
+ */
16
+ var maxSubArray = function ( nums ) {
17
+ for ( let i = 1 ; i < nums . length ; i ++ ) {
18
+ if ( nums [ i - 1 ] > 0 ) {
19
+ nums [ i ] += nums [ i - 1 ] ;
20
+ }
21
+ }
22
+
23
+ return Math . max ( ...nums ) ;
24
+ } ;
You can’t perform that action at this time.
0 commit comments