public List<String> summaryRanges(int[] nums) {
        List<String> result = new ArrayList<String>();
        if (nums == null || nums.length == 0) return result;
        for (int i = 0; i < nums.length; ++i) {
            int prev = nums[i];
            while (i < nums.length - 1 && nums[i] + 1 == nums[i + 1]) {
                ++i;
            }
            if (prev == nums[i]) {
                result.add(prev + "");
            } else {
                result.add(prev + "->" + nums[i]);
            }
        }
        return result;
    }