Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func maxProduct(_ nums: [Int]) -> Int {
- var minSub = 1
- var maxSub = 1
- var res = Int.min
- for (index, n) in nums.enumerated(){
- let possible1 = n * minSub
- let possible2 = n * maxSub
- minSub = min(n , possible1, possible2)
- maxSub = max(n , possible1, possible2)
- res = max(res , maxSub)
- }
- return res
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement