Minimize Deviation in Array LeetCode solution in Java
1class Solution {2public int minimumDeviation(int[] nums) {3TreeSet<Integer> temp = new TreeSet<>();4for (int i : nums) {5if (i % 2 == 0) {6temp.add(i);7} else {8temp.add(i * 2);9}10}1112int md = temp.last() - temp.first();13int m = 0;1415while (temp.size() > 0 && temp.last() % 2 == 0) {16m = temp.last();17temp.remove(m);18temp.add(m / 2);1920md = Math.min(md, temp.last() - temp.first());21}22return md;23}24}