Missing Ranges

题目看不到,所以网上搜刮

http://www.danielbit.com/blog/puzzle/leetcode/leetcode-missing-ranges

学习了一下

public class Solution {

    public List<String> findMissingRanges(int[] vals, int start, int end) {

        int pre = start-1;

        List<String> res= new List<String>();

        for(int i=0;i<=vals.length;i++){

            int cur = (i==vals.length?)end: vals[i];

            if(cur-pre>1){

                res.add(getRange(vals, pre+1, cur-1));

            }

            pre = cur;

        }

        return res;

    }

    public String getRange(int[] v, int f, int t){

        return (f==t?)String.valueOf(f): from+"->"+ to;

    }

}

 

你可能感兴趣的:(SSI)