859. Buddy Strings】的更多相关文章

problem 859. Buddy Strings solution: class Solution { public: bool buddyStrings(string A, string B) { if(A.size()!=B.size()) return false; if(A==B && unordered_set<char>(A.begin(), A.end()).size()<A.size()) return true; vector<int>…
Question 859. Buddy Strings Solution 题目大意: 两个字符串,其中一个字符串任意两个字符互换后与另一个字符串相等,只能互换一次 思路: diff 记录不同字符数 两个字符串长度不同 return false 两个字符串长度相同: abc abd 无重复,diff == 1 ca[3] != cb[3] return false abc abc 无重复,diff == 0 return false ab ba 无重复,diff == 2 return true…
Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B. Example 1: Input: A = "ab", B = "ba" Output: true Example 2: Input: A = "ab", B = "ab&q…
Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B. Example 1: Input: A = "ab", B = "ba" Output: true Example 2: Input: A = "ab", B = "ab&q…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcode.com/problems/buddy-strings/description/ 题目描述 Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A…
class Solution { public: bool buddyStrings(string A, string B) { int lenA=A.length(); int lenB=B.length(); if(lenA!=lenB) return false; unordered_set<char>cset(A.begin(),A.end()); if(A==B&&cset.size()<lenA) return true; vector<int>…
859. 亲密字符串 859. Buddy Strings 题目描述 给定两个由小写字母构成的字符串 A 和 B,只要我们可以通过交换 A 中的两个字母得到与 B 相等的结果,就返回 true:否则返回 false. 每日一算法2019/5/26Day 23LeetCode859. Buddy Strings 示例 1: 输入: A = "ab", B = "ba" 输出: true 示例 2: 输入: A = "ab", B = "a…
Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B. Example 1: Input: A = "ab", B = "ba" Output: true Example 2: Input: A = "ab", B = "ab&q…
Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B. Example 1: Input: A = "ab", B = "ba" Output: true Example 2: Input: A = "ab", B = "ab&q…
Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B. Example 1: Input: A = "ab", B = "ba" Output: true Example 2: Input: A = "ab", B = "ab&q…