Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d23fe25

Browse files
[LEET-3438] add 3438
1 parent df7a9cb commit d23fe25

File tree

2 files changed

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

2 files changed

+25
-0
lines changed

‎paginated_contents/algorithms/4th_thousand/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
| 3477 | [Fruits Into Baskets II](https://leetcode.com/problems/fruits-into-baskets-ii/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3477.java) | | Easy |
66
| 3471 | [Find the Largest Almost Missing Integer](https://leetcode.com/problems/find-the-largest-almost-missing-integer/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java) | | Easy |
77
| 3450 | [Maximum Students on a Single Bench](https://leetcode.com/problems/maximum-students-on-a-single-bench/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3450.java) | | Easy |
8+
| 3438 | [Find Valid Pair of Adjacent Digits in String](https://leetcode.com/problems/find-valid-pair-of-adjacent-digits-in-string/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3438.java) | | Easy |
89
| 3402 | [Minimum Operations to Make Columns Strictly Increasing](https://leetcode.com/problems/minimum-operations-to-make-columns-strictly-increasing/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3402.java) | | Easy |
910
| 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy |
1011
| 3392 | [Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3392.java) | | Easy |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _3438 {
7+
public static class Solution1 {
8+
public String findValidPair(String s) {
9+
Map<Integer, Integer> map = new HashMap<>();
10+
for (char c : s.toCharArray()) {
11+
int val = Character.getNumericValue(c);
12+
map.put(val, map.getOrDefault(val, 0) + 1);
13+
}
14+
for (int i = 0; i < s.length() - 1; i++) {
15+
int val = Character.getNumericValue(s.charAt(i));
16+
int nextVal = Character.getNumericValue(s.charAt(i + 1));
17+
if (val != nextVal && val == map.get(val) && nextVal == map.get(nextVal)) {
18+
return val + "" + nextVal + "";
19+
}
20+
}
21+
return "";
22+
}
23+
}
24+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /