# 0900. RLE Iterator ###### tags: `Leetcode` `Medium` Link: https://leetcode.com/problems/rle-iterator/ ## Code ```java= class RLEIterator { int idx; int[] arr; public RLEIterator(int[] encoding) { idx = 0; this.arr = encoding; } public int next(int n) { int len = arr.length; int ans = 0; while(idx<len && n>arr[idx]){ n = n-arr[idx]; idx+=2; } if(idx==len) return -1; arr[idx] = arr[idx]-n; return arr[idx+1]; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up