Skip to content

Commit e43ff77

Browse files
committedJul 14, 2024·
add 3216
1 parent 1ea298c commit e43ff77

File tree

2 files changed

+28
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/fourththousand

2 files changed

+28
-0
lines changed
 

‎paginated_contents/algorithms/4th_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| # | Title | Solutions | Video | Difficulty | Tag
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
3+
| 3216 | [Lexicographically Smallest String After a Swap](https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3216.java) | | Easy | Greedy
34
| 3212 | [Count Submatrices With Equal Frequency of X and Y](https://leetcode.com/problems/count-submatrices-with-equal-frequency-of-x-and-y/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3212.java) | | Medium | Prefix Sum
45
| 3211 | [Generate Binary Strings Without Adjacent Zeros](https://leetcode.com/problems/generate-binary-strings-without-adjacent-zeros/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3211.java) | | Medium | Recursion, Backtracking
56
| 3210 | [Find the Encrypted String](https://leetcode.com/problems/find-the-encrypted-string/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3210.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
public class _3216 {
4+
public static class Solution1 {
5+
public String getSmallestString(String s) {
6+
for (int i = 0; i < s.length() - 1; i++) {
7+
if (s.charAt(i) > s.charAt(i + 1) && sameParity(s.charAt(i), s.charAt(i + 1))) {
8+
char[] charArray = s.toCharArray();
9+
char tmp = charArray[i];
10+
charArray[i] = charArray[i + 1];
11+
charArray[i + 1] = tmp;
12+
return new String(charArray);
13+
}
14+
}
15+
return s;
16+
}
17+
18+
private boolean sameParity(char c1, char c2) {
19+
int num1 = Integer.parseInt(c1 + "");
20+
int num2 = Integer.parseInt(c2 + "");
21+
if (num2 % 2 == 0 && num1 % 2 == 0 || (num2 % 2 == 1 && num1 % 2 == 1)) {
22+
return true;
23+
}
24+
return false;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)
Please sign in to comment.