File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 224
224
| 1832| [ 判断句子是否为全字母句] ( https://leetcode.cn/problems/check-if-the-sentence-is-pangram/ ) | [ JavaScript] ( ./algorithms/check-if-the-sentence-is-pangram.js ) | Easy|
225
225
| 1863| [ 找出所有子集的异或总和再求和] ( https://leetcode.cn/problems/sum-of-all-subset-xor-totals/ ) | [ JavaScript] ( ./algorithms/sum-of-all-subset-xor-totals.js ) | Easy|
226
226
| 1945| [ 字符串转化后的各位数字之和] ( https://leetcode.cn/problems/sum-of-digits-of-string-after-convert/ ) | [ JavaScript] ( ./algorithms/sum-of-digits-of-string-after-convert.js ) | Easy|
227
+ | 2202| [ K 次操作后最大化顶端元素] ( https://leetcode.cn/problems/maximize-the-topmost-element-after-k-moves/ ) | [ JavaScript] ( ./algorithms/maximize-the-topmost-element-after-k-moves.js ) | Medium|
227
228
| 2032| [ 至少在两个数组中出现的值] ( https://leetcode.cn/problems/two-out-of-three/ ) | [ JavaScript] ( ./algorithms/two-out-of-three.js ) | Easy|
228
229
| 2042| [ 检查句子中的数字是否递增] ( https://leetcode.cn/problems/check-if-numbers-are-ascending-in-a-sentence/ ) | [ JavaScript] ( ./algorithms/check-if-numbers-are-ascending-in-a-sentence.js ) | Easy|
229
230
| 2283| [ 判断一个数的数字计数是否等于数位的值] ( https://leetcode.cn/problems/check-if-number-has-equal-digit-count-and-digit-value/ ) | [ JavaScript] ( ./algorithms/check-if-number-has-equal-digit-count-and-digit-value.js ) | Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } nums
3
+ * @param {number } k
4
+ * @return {number }
5
+ */
6
+ var maximumTop = function ( nums , k ) {
7
+ // 分类讨论
8
+ const n = nums . length ;
9
+
10
+ if ( n === 1 ) {
11
+ if ( k % 2 === 1 ) {
12
+ return - 1 ;
13
+ }
14
+ return nums [ 0 ] ;
15
+ }
16
+ if ( k <= 1 ) {
17
+ return nums [ k ] ;
18
+ }
19
+ if ( k > n ) {
20
+ return Math . max ( ...nums ) ;
21
+ }
22
+ if ( k === n ) {
23
+ return Math . max ( ...nums . slice ( 0 , n - 1 ) ) ;
24
+ }
25
+ return Math . max ( ...nums . slice ( 0 , k - 1 ) , nums [ k ] ) ;
26
+ } ;
You can’t perform that action at this time.
0 commit comments