Advertisement
HXXXXJ

755. Pour Water

Mar 18th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.54 KB | None | 0 0
  1.     func pourWater(_ heights: [Int], _ V: Int, _ K: Int) -> [Int] {
  2.         var res = heights
  3.        
  4.         for i in 1 ... V{
  5.             var cur = K
  6.             while cur > 0 && res[cur - 1] <= res[cur]{
  7.                 cur -= 1
  8.             }
  9.             while cur < res.count - 1 && res[cur + 1] <= res[cur]{
  10.                 cur += 1
  11.             }
  12.            
  13.             while cur > K && res[cur - 1] <= res[cur]{
  14.                 cur -= 1
  15.             }
  16.             res[cur] += 1
  17.         }
  18.         return res
  19.        
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement