File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2270. Number of Ways to Split Array
3
+ * https://leetcode.com/problems/number-of-ways-to-split-array/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given a 0-indexed integer array nums of length n.
7
+ *
8
+ * nums contains a valid split at index i if the following are true:
9
+ * - The sum of the first i + 1 elements is greater than or equal to the sum of the
10
+ * last n - i - 1 elements.
11
+ * - There is at least one element to the right of i. That is, 0 <= i < n - 1.
12
+ *
13
+ * Return the number of valid splits in nums.
14
+ */
15
+
16
+ /**
17
+ * @param {number[] } nums
18
+ * @return {number }
19
+ */
20
+ var waysToSplitArray = function ( nums ) {
21
+ const total = nums . reduce ( ( a , b ) => a + b ) ;
22
+ let result = 0 ;
23
+
24
+ for ( let i = 0 , sum = 0 ; i < nums . length - 1 ; i ++ ) {
25
+ sum += nums [ i ] ;
26
+ if ( sum >= total - sum ) {
27
+ result ++ ;
28
+ }
29
+ }
30
+
31
+ return result ;
32
+ } ;
Original file line number Diff line number Diff line change 704
704
2215|[ Find the Difference of Two Arrays] ( ./2215-find-the-difference-of-two-arrays.js ) |Easy|
705
705
2235|[ Add Two Integers] ( ./2235-add-two-integers.js ) |Easy|
706
706
2244|[ Minimum Rounds to Complete All Tasks] ( ./2244-minimum-rounds-to-complete-all-tasks.js ) |Medium|
707
+ 2270|[ Number of Ways to Split Array] ( ./2270-number-of-ways-to-split-array.js ) |Medium|
707
708
2300|[ Successful Pairs of Spells and Potions] ( ./2300-successful-pairs-of-spells-and-potions.js ) |Medium|
708
709
2336|[ Smallest Number in Infinite Set] ( ./2336-smallest-number-in-infinite-set.js ) |Medium|
709
710
2342|[ Max Sum of a Pair With Equal Sum of Digits] ( ./2342-max-sum-of-a-pair-with-equal-sum-of-digits.js ) |Medium|
You can’t perform that action at this time.
0 commit comments