package leetcode;

/**
 * https://leetcode.com/problems/minimum-distance-to-the-target-element/
 */
public class Problem1848 {
    public int getMinDistance(int[] nums, int target, int start) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1848 prob = new Problem1848();
        System.out.println(prob.getMinDistance(new int[]{1,2,3,4,5}, 5, 3)); // 1
        System.out.println(prob.getMinDistance(new int[]{1}, 1, 0)); // 0
        System.out.println(prob.getMinDistance(new int[]{1,1,1,1,1,1,1,1,1,1}, 1, 0)); // 0
    }
}

@@ -199,82 +199,121 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args
+int answer = Integer.MAX_VALUE;%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            if (nums%5Bi%5D == target
 ) %7B%0A
@@ -324,293 +324,110 @@
     
-Problem1848 prob = new Problem1848();%0A        System.out.println(prob.getMinDistance(new int%5B%5D%7B1,2,3,4,5%7D, 5, 3)); // 1%0A        System.out.println(prob.getMinDistance(new int%5B%5D%7B1%7D, 1, 0)); // 0%0A        System.out.println(prob.getMinDistance(new int%5B%5D%7B1,1,1,1,1,1,1,1,1,1%7D, 1, 0)); // 0
+        answer = Math.min(answer, Math.abs(i - start));%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1848