Advertisement
Alexxik

Untitled

Sep 18th, 2023 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.43 KB | None | 0 0
  1. func findMaxConsecutiveOnes(_ nums: [Int]) -> Int {
  2.    
  3.     var result = 0
  4.     var current = 0
  5.    
  6.     var r = 0
  7.    
  8.     while r < nums.count {
  9.        
  10.         if nums[r] == 1 {
  11.             current += 1
  12.             result = max(current, result)
  13.         } else if nums[r] == 0 {
  14.             current = 0
  15.         }
  16.        
  17.         r += 1
  18.     }
  19.     return result
  20. }
  21.  
  22. let nums = [1,0,1,1,0,1]
  23. findMaxConsecutiveOnes(nums)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement