File tree 2 files changed +41
-1
lines changed
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,445 LeetCode solutions in JavaScript
1
+ # 1,446 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1268
1268
1641|[ Count Sorted Vowel Strings] ( ./solutions/1641-count-sorted-vowel-strings.js ) |Medium|
1269
1269
1642|[ Furthest Building You Can Reach] ( ./solutions/1642-furthest-building-you-can-reach.js ) |Medium|
1270
1270
1643|[ Kth Smallest Instructions] ( ./solutions/1643-kth-smallest-instructions.js ) |Hard|
1271
+ 1646|[ Get Maximum in Generated Array] ( ./solutions/1646-get-maximum-in-generated-array.js ) |Easy|
1271
1272
1657|[ Determine if Two Strings Are Close] ( ./solutions/1657-determine-if-two-strings-are-close.js ) |Medium|
1272
1273
1668|[ Maximum Repeating Substring] ( ./solutions/1668-maximum-repeating-substring.js ) |Easy|
1273
1274
1669|[ Merge In Between Linked Lists] ( ./solutions/1669-merge-in-between-linked-lists.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1646. Get Maximum in Generated Array
3
+ * https://leetcode.com/problems/get-maximum-in-generated-array/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated
7
+ * in the following way:
8
+ * - nums[0] = 0
9
+ * - nums[1] = 1
10
+ * - nums[2 * i] = nums[i] when 2 <= 2 * i <= n
11
+ * - nums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n
12
+ *
13
+ * Return the maximum integer in the array nums.
14
+ */
15
+
16
+ /**
17
+ * @param {number } n
18
+ * @return {number }
19
+ */
20
+ var getMaximumGenerated = function ( n ) {
21
+ if ( n === 0 ) return 0 ;
22
+
23
+ const generatedArray = new Array ( n + 1 ) . fill ( 0 ) ;
24
+ generatedArray [ 1 ] = 1 ;
25
+ let maximumValue = 1 ;
26
+
27
+ for ( let i = 1 ; i <= Math . floor ( n / 2 ) ; i ++ ) {
28
+ if ( 2 * i <= n ) {
29
+ generatedArray [ 2 * i ] = generatedArray [ i ] ;
30
+ maximumValue = Math . max ( maximumValue , generatedArray [ 2 * i ] ) ;
31
+ }
32
+ if ( 2 * i + 1 <= n ) {
33
+ generatedArray [ 2 * i + 1 ] = generatedArray [ i ] + generatedArray [ i + 1 ] ;
34
+ maximumValue = Math . max ( maximumValue , generatedArray [ 2 * i + 1 ] ) ;
35
+ }
36
+ }
37
+
38
+ return maximumValue ;
39
+ } ;
You can’t perform that action at this time.
0 commit comments