File tree Expand file tree Collapse file tree
paginated_contents/algorithms/4th_thousand
src/main/java/com/fishercoder/solutions/fourththousand Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212| 3945 | [ Digit Frequency Score] ( https://leetcode.com/problems/digit-frequency-score/ ) | [ Java] ( https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3945.java ) | | Easy |
1313| 3941 | [ Password Strength] ( https://leetcode.com/problems/password-strength/ ) | [ Java] ( https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3941.java ) | | Easy |
1414| 3940 | [ Limit Occurrences in Sorted Array] ( https://leetcode.com/problems/limit-occurrences-in-sorted-array/ ) | [ Java] ( https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3940.java ) | | Easy |
15+ | 3936 | [ Minimum Swaps to Move Zeros to End] ( https://leetcode.com/problems/minimum-swaps-to-move-zeros-to-end/ ) | [ Java] ( https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3936.java ) | | Easy |
1516| 3925 | [ Concatenate Array With Reverse] ( https://leetcode.com/problems/concatenate-array-with-reverse/ ) | [ Java] ( https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3925.java ) | | Easy |
1617| 3913 | [ Sort Vowels by Frequency] ( https://leetcode.com/problems/sort-vowels-by-frequency/ ) | [ Java] ( https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3913.java ) | | Easy |
1718| 3908 | [ Valid Digit Number] ( https://leetcode.com/problems/valid-digit-number/ ) | [ Java] ( https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3908.java ) | | Easy |
Original file line number Diff line number Diff line change 1+ package com .fishercoder .solutions .fourththousand ;
2+
3+ public class _3936 {
4+ public static class Solution1 {
5+ /**
6+ * My completely original solution:
7+ * two pointer technique:
8+ * left pointer keeps looking for the zero number
9+ * right pointer keeps looking for the non-zero number
10+ * once we find a pair, increase the swap count;
11+ * if we don't find a pair, keep moving both pointers.
12+ *
13+ */
14+ public int minimumSwaps (int [] nums ) {
15+ int minsSwaps = 0 ;
16+ int left = 0 ;
17+ int right = nums .length - 1 ;
18+ while (left < right ) {
19+ while (left < right && nums [right ] == 0 ) {
20+ right --;
21+ }
22+ if (left >= right ) {
23+ return minsSwaps ;
24+ }
25+ while (left < right && nums [left ] != 0 ) {
26+ left ++;
27+ }
28+ if (left >= right ) {
29+ return minsSwaps ;
30+ }
31+ minsSwaps ++;
32+ left ++;
33+ right --;
34+ }
35+ return minsSwaps ;
36+ }
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments