Advertisement
HXXXXJ

DrawArc - onlyneed count

Feb 22nd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.45 KB | None | 0 0
  1. func countDraw(_ arr:[Int]) -> Int{
  2.   guard arr.count > 0 else {return 0}
  3.   var temp = arr
  4.    
  5.   while temp[0] != 0 {
  6.     //need to check count!!!, for all 1 case
  7.     // todo
  8.     let f = temp.removeFirst()
  9.     temp.append(f)
  10.   }
  11.   var res = 0
  12.   var i = 0
  13.   while i < temp.count{
  14.     if temp[i] == 0 {
  15.       i += 1
  16.       continue
  17.     }
  18.     res += 1
  19.     i += 1
  20.     while i < temp.count && temp[i] != 0 {
  21.       i += 1
  22.     }
  23.   }
  24.   return res
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement