File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 238238| 2335| [ 装满杯子需要的最短总时长] ( https://leetcode.cn/problems/minimum-amount-of-time-to-fill-cups/ ) | [ JavaScript] ( ./algorithms/minimum-amount-of-time-to-fill-cups.js ) | Easy|
239239| 2341| [ 数组能形成多少数对] ( https://leetcode.cn/problems/maximum-number-of-pairs-in-array/ ) | [ JavaScript] ( ./algorithms/maximum-number-of-pairs-in-array.js ) | Easy|
240240| 2351| [ 第一个出现两次的字母] ( https://leetcode.cn/problems/first-letter-to-appear-twice/ ) | [ JavaScript] ( ./algorithms/first-letter-to-appear-twice.js ) | Easy|
241+ | 2357| [ 使数组中所有元素都等于零] ( https://leetcode.cn/problems/make-array-zero-by-subtracting-equal-amounts/ ) | [ JavaScript] ( ./algorithms/make-array-zero-by-subtracting-equal-amounts.js ) | Easy|
241242| 6354| [ 找出数组的串联值] ( https://leetcode.cn/problems/find-the-array-concatenation-value/ ) | [ JavaScript] ( ./algorithms/find-the-array-concatenation-value.js ) | Easy|
242243| 6362| [ 合并两个二维数组 - 求和法] ( https://leetcode.cn/problems/merge-two-2d-arrays-by-summing-values/ ) | [ JavaScript] ( ) | Easy|
243244| 面试题 04.12| [ 面试题 04.12. 求和路径] ( https://leetcode.cn/problems/paths-with-sum-lcci/ ) | [ JavaScript] ( ./algorithms/paths-with-sum-lcci.js ) | Medium|
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } nums
3+ * @return {number }
4+ */
5+ var minimumOperations = function ( nums ) {
6+ // 排序 + 模拟
7+ nums . sort ( ( a , b ) => a - b ) ;
8+ let count = 0 ;
9+ // 0 1 3 5 5 -> 0 0 2 4 4 -> 0 0 0 2 2 -> 0 0 0 0 0
10+ for ( let i = 0 ; i < nums . length ; i ++ ) {
11+ let curr = nums [ i ] ;
12+ if ( nums [ i ] !== 0 ) {
13+ for ( let j = i ; j < nums . length ; j ++ ) {
14+ nums [ j ] -= curr ;
15+ }
16+ count ++ ;
17+ }
18+ }
19+ return count ;
20+ } ;
21+
22+ // 其实就是找不重复数字的个数
23+ var minimumOperations = function ( nums ) {
24+ nums . sort ( ( a , b ) => a - b ) ;
25+ let count = 0 ;
26+
27+ for ( let i = 0 ; i < nums . length ; i ++ ) {
28+ if ( nums [ i ] !== 0 && nums [ i ] !== nums [ i + 1 ] ) {
29+ count ++ ;
30+ }
31+ }
32+ return count ;
33+ }
34+
35+ var minimumOperations = function ( nums ) {
36+ const set = new Set ( ) ;
37+
38+ for ( let i = 0 ; i < nums . length ; i ++ ) {
39+ if ( nums [ i ] !== 0 ) {
40+ set . add ( nums [ i ] ) ;
41+ }
42+ }
43+
44+ return set . size ;
45+ }
You can’t perform that action at this time.
0 commit comments