Java Clean Solution | Daily Challenges
Complexity\n- Time complexity:O(n*X)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity:$$O(n*X)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n// class Solution {\n//     public int minSwaps(int[] nums) {\n//         int one = 0;\n//         for (int num : nums) {\n//             one += num;\n//         }\n\n//         int cnt_one = 0, window = 0;\n//         for (int i = 0; i < nums.length + one; i++) {\n//             if (i >= one && nums[i - one] == 1) {\n//                 cnt_one--;\n//             }\n//             if (nums[i % nums.length] == 1) {\n//                 cnt_one++;\n//             }\n\n//             window = Math.max(cnt_one, window);\n//         }\n//         return one - window;\n//     }\n// }\n\n\n\n// SLIDING WINDOW....\nclass Solution {\n    public int minSwaps(int[] nums) {\n        int one = 0;\n        for (int num : nums) {\n            one += num;\n        }\n\n        int res = nums.length;\n        for (int i = 0, j = 0, cnt = 0; i < nums.length; i++) {\n            while (j - i < one) {\n                cnt += nums[j % nums.length];\n                j++;\n            }\n\n            res = Math.min(res, one - cnt);\n            cnt -= nums[i];\n        }\n        return res;\n    }\n}\n```
['Array', 'Math', 'Greedy', 'Sliding Window', 'Java']