File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } nums
3+ * @param {number } k
4+ * @return {number }
5+ */
6+ let subarraySum = function ( nums , k ) {
7+ let n = nums . length
8+ if ( ! n ) {
9+ return 0
10+ }
11+
12+ let res = 0
13+ for ( let i = 0 ; i < n ; i ++ ) {
14+ let total = 0
15+ for ( let j = i ; j < n ; j ++ ) {
16+ total += nums [ j ]
17+ if ( total === k ) {
18+ res += 1
19+ }
20+ }
21+ }
22+ return res
23+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[][] } matrix
3+ * @return {void } Do not return anything, modify matrix in-place instead.
4+ */
5+ let setZeroes = function ( matrix ) {
6+ let maxY = matrix . length
7+ if ( ! maxY ) return
8+ let maxX = matrix [ 0 ] . length
9+
10+ let handledRows = [ ]
11+ let handledColumns = [ ]
12+
13+ let zeros = [ ]
14+ for ( let y = 0 ; y < maxY ; y ++ ) {
15+ for ( let x = 0 ; x < maxX ; x ++ ) {
16+ let val = matrix [ y ] [ x ]
17+ if ( val === 0 ) {
18+ zeros . push ( [ y , x ] )
19+ }
20+ }
21+ }
22+
23+ for ( let [ y , x ] of zeros ) {
24+ if ( ! handledRows [ x ] ) {
25+ for ( let i = 0 ; i < maxY ; i ++ ) {
26+ matrix [ i ] [ x ] = 0
27+ }
28+ handledRows [ x ] = true
29+ }
30+ if ( ! handledColumns [ y ] ) {
31+ for ( let i = 0 ; i < maxX ; i ++ ) {
32+ matrix [ y ] [ i ] = 0
33+ }
34+ handledColumns [ y ] = true
35+ }
36+ }
37+ } ;
You can’t perform that action at this time.
0 commit comments