package leetcode;

/**
 * https://leetcode.com/problems/shortest-unsorted-continuous-subarray/
 */
public class Problem581 {
    public int findUnsortedSubarray(int[] nums) {

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

        }
        return 0;
    }

    public static void main(String[] args) {
        Problem581 prob = new Problem581();
        System.out.println(prob.findUnsortedSubarray(new int[]{2, 6, 4, 8, 10, 9, 15})); // 5
        System.out.println(prob.findUnsortedSubarray(new int[]{2, 6, 4, 8, 10, 7, 9})); // 6    
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -198,68 +198,288 @@
 ) %7B%0A
-%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A%0A        %7D%0A
+        int%5B%5D sorted = Arrays.copyOf(nums, nums.length);%0A        Arrays.sort(sorted);%0A        int count = 0;%0A        int i = 0;%0A        int j = 0;%0A        while (i %3C nums.length && nums%5Bi++%5D == sorted%5Bj++%5D) %7B%0A            count++;%0A        %7D%0A        if (nums.length == count) %7B%0A    
     
@@ -500,290 +500,191 @@
     
+   
+ 
 %7D
-%0A
 %0A    
-public static void main(String%5B%5D args) %7B%0A        Problem581 prob = new Problem581();%0A        System.out.println(prob.findUnsortedSubarray(new int%5B%5D%7B2, 6, 4, 8, 10, 9, 15%7D)); // 5%0A        System.out.println(prob.findUnsortedSubarray(new int%5B%5D%7B2, 6, 4, 8, 10, 7, 9%7D)); // 6    
+    i = nums.length - 1;%0A        j = nums.length - 1;%0A        while (i %3E= 0 && nums%5Bi--%5D == sorted%5Bj--%5D) %7B%0A            count++;%0A        %7D%0A        return nums.length - count;
 %0A   

Solve problem 581