Created
October 4, 2017 15:13
-
-
Save cixuuz/1230642313f811ed623dc4b969f9170f to your computer and use it in GitHub Desktop.
[163. Missing Ranges] #leetcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Solution { | |
| public List<String> findMissingRanges(int[] nums, int lower, int upper) { | |
| List<String> res = new ArrayList<>(); | |
| for(int i : nums) { | |
| if(i > lower) res.add(lower+((i-1 > lower)?"->"+(i-1):"")); | |
| if(i == upper) return res; // Avoid overflow | |
| lower = i+1; | |
| } | |
| if(lower <= upper) res.add(lower + ((upper > lower)?"->"+(upper):"")); | |
| return res; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment