Advertisement
HXXXXJ

DrawArc - need call

Feb 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.84 KB | None | 0 0
  1.  
  2. func drawArc(_ arr: [Int]){
  3.     guard arr.count > 0 else { return }
  4.     var l = 0
  5.     var r = arr.count - 1
  6.    
  7.     // need to handle corner case
  8.     if arr[l] == 1 && arr[r] == 1 {
  9.         while l < arr.count && arr[l] == 1 {
  10.             l += 1
  11.         }
  12.         if l == arr.count {   // all 1
  13.             print("at \(0) length \(arr.count)")
  14.             return
  15.         }
  16.         while r >= l && arr[r] == 1 {
  17.             r -= 1
  18.         }
  19.         print("at \(r + 1) length \(arr.count - 1 - r + l)")
  20.     }
  21.    
  22.     // l at first point to calc, r at last calc position
  23.     while l <= r {
  24.         if arr[l] == 1 {
  25.             let start = l
  26.             l += 1
  27.             while l <= r && arr[l] == 1 {
  28.                 l += 1
  29.             }
  30.             print("at \(start) length \(l - start)")
  31.         }
  32.         l += 1
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement