@@ -0,0 +1,1414 @@
+package com.freetymekiyan.algorithms.level.medium;%0A%0Aimport org.junit.After;%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * Given a sorted integer array without duplicates, return the summary of its ranges.%0A * %3Cp%3E%0A * For example, given %5B0,1,2,4,5,7%5D, return %5B%220-%3E2%22,%224-%3E5%22,%227%22%5D.%0A * %3Cp%3E%0A * %3Cp%3E%0A * Tags: Array%0A * Similar Problems: (M) Missing Ranges, (H) Data Stream as Disjoint Intervals%0A */%0Apublic class SummaryRanges %7B%0A%0A    private SummaryRanges s;%0A%0A    public List%3CString%3E summaryRanges(int%5B%5D nums) %7B%0A        List%3CString%3E res = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            int end = i + 1;%0A            while (end %3C nums.length && nums%5Bend%5D - nums%5Bend - 1%5D == 1) %7B%0A                end++;%0A            %7D%0A            if (end - i == 1) %7B%0A                res.add(Integer.toString(nums%5Bi%5D));%0A            %7D else %7B%0A                res.add(nums%5Bi%5D + %22-%3E%22 + nums%5Bend - 1%5D);%0A                i = end - 1;%0A            %7D%0A        %7D%0A        return res;%0A    %7D%0A%0A    @Before%0A    public void setUp() %7B%0A        s = new SummaryRanges();%0A    %7D%0A%0A    @Test%0A    public void testExamples() %7B%0A        int%5B%5D nums = %7B0, 1, 2, 4, 5, 7%7D;%0A        List%3CString%3E res = s.summaryRanges(nums);%0A        Assert.assertEquals(%22%5B0-%3E2, 4-%3E5, 7%5D%22, res.toString());%0A    %7D%0A%0A    @After%0A    public void tearDown() %7B%0A        s = null;%0A    %7D%0A%0A%7D%0A

add Summary Ranges