Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func pourWater(_ heights: [Int], _ V: Int, _ K: Int) -> [Int] {
- var res = heights
- for i in 1 ... V{
- var cur = K
- while cur > 0 && res[cur - 1] <= res[cur]{
- cur -= 1
- }
- while cur < res.count - 1 && res[cur + 1] <= res[cur]{
- cur += 1
- }
- while cur > K && res[cur - 1] <= res[cur]{
- cur -= 1
- }
- res[cur] += 1
- }
- return res
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement