Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d9f0c2c

Browse files
committedFeb 6, 2025·
[week9](gmlwls96) Maximum Product Subarray
1 parent f7d4d2d commit d9f0c2c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎maximum-product-subarray/gmlwls96.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
fun maxProduct(nums: IntArray): Int {
3+
var max = 1
4+
var min = 1
5+
var result = nums[0]
6+
nums.forEach { num ->
7+
val v1 = min * num
8+
val v2 = max * num
9+
min = min(min(v1, v2), num)
10+
max = max(max(v1, v2), num)
11+
result = max(max, result)
12+
}
13+
return result
14+
}
15+
}

0 commit comments

Comments
 (0)