Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func drawArc(_ arr: [Int]){
- guard arr.count > 0 else { return }
- var l = 0
- var r = arr.count - 1
- // need to handle corner case
- if arr[l] == 1 && arr[r] == 1 {
- while l < arr.count && arr[l] == 1 {
- l += 1
- }
- if l == arr.count { // all 1
- print("at \(0) length \(arr.count)")
- return
- }
- while r >= l && arr[r] == 1 {
- r -= 1
- }
- print("at \(r + 1) length \(arr.count - 1 - r + l)")
- }
- // l at first point to calc, r at last calc position
- while l <= r {
- if arr[l] == 1 {
- let start = l
- l += 1
- while l <= r && arr[l] == 1 {
- l += 1
- }
- print("at \(start) length \(l - start)")
- }
- l += 1
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement