859. Buddy Strings Easy

@problem@discussion
#Hash Table#String



1/**
2 * [859] Buddy Strings
3 *
4 * Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal, otherwise, return false.
5 * Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at s[i] and s[j].
6 * 
7 * 	For example, swapping at indices 0 and 2 in "abcd" results in "cbad".
8 * 
9 *  
10 * Example 1:
11 * 
12 * Input: s = "ab", goal = "ba"
13 * Output: true
14 * Explanation: You can swap s[0] = 'a' and s[1] = 'b' to get "ba", which is equal to goal.
15 * 
16 * Example 2:
17 * 
18 * Input: s = "ab", goal = "ab"
19 * Output: false
20 * Explanation: The only letters you can swap are s[0] = 'a' and s[1] = 'b', which results in "ba" != goal.
21 * 
22 * Example 3:
23 * 
24 * Input: s = "aa", goal = "aa"
25 * Output: true
26 * Explanation: You can swap s[0] = 'a' and s[1] = 'a' to get "aa", which is equal to goal.
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	1 <= s.length, goal.length <= 2 * 10^4
32 * 	s and goal consist of lowercase letters.
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/buddy-strings/
38// discuss: https://leetcode.com/problems/buddy-strings/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn buddy_strings(s: String, goal: String) -> bool {
44        false
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_859() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.