3438. Find Valid Pair of Adjacent Digits in String Easy
1/**
2 * [3438] Find Valid Pair of Adjacent Digits in String
3 *
4 * You are given a string s consisting only of digits. A valid pair is defined as two adjacent digits in s such that:
5 *
6 * The first digit is not equal to the second.
7 * Each digit in the pair appears in s exactly as many times as its numeric value.
8 *
9 * Return the first valid pair found in the string s when traversing from left to right. If no valid pair exists, return an empty string.
10 *
11 * <strong class="example">Example 1:
12 * <div class="example-block">
13 * Input: <span class="example-io">s = "2523533"</span>
14 * Output: <span class="example-io">"23"</span>
15 * Explanation:
16 * Digit '2' appears 2 times and digit '3' appears 3 times. Each digit in the pair "23" appears in s exactly as many times as its numeric value. Hence, the output is "23".
17 * </div>
18 * <strong class="example">Example 2:
19 * <div class="example-block">
20 * Input: <span class="example-io">s = "221"</span>
21 * Output: <span class="example-io">"21"</span>
22 * Explanation:
23 * Digit '2' appears 2 times and digit '1' appears 1 time. Hence, the output is "21".
24 * </div>
25 * <strong class="example">Example 3:
26 * <div class="example-block">
27 * Input: <span class="example-io">s = "22"</span>
28 * Output: <span class="example-io">""</span>
29 * Explanation:
30 * There are no valid adjacent pairs.
31 * </div>
32 *
33 * Constraints:
34 *
35 * 2 <= s.length <= 100
36 * s only consists of digits from '1' to '9'.
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/find-valid-pair-of-adjacent-digits-in-string/
42// discuss: https://leetcode.com/problems/find-valid-pair-of-adjacent-digits-in-string/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn find_valid_pair(s: String) -> String {
48 String::new()
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_3438() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.