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> diff;
for(int i=; i<A.size(); ++i)
{
if(A[i]!=B[i]) diff.push_back(i);
}
return diff.size()== && A[diff[]]==B[diff[]] && A[diff[]]==B[diff[]];
}
};

参考

1. Leetcode_easy_859. Buddy Strings;

2. grandyang;

3. Discuss;

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

  1. 【LeetCode】859. Buddy Strings 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcod ...

  2. 【Leetcode_easy】1170. Compare Strings by Frequency of the Smallest Character

    problem 1170. Compare Strings by Frequency of the Smallest Character 参考 1. Leetcode_easy_1170. Compa ...

  3. 859. Buddy Strings - LeetCode

    Question 859. Buddy Strings Solution 题目大意: 两个字符串,其中一个字符串任意两个字符互换后与另一个字符串相等,只能互换一次 思路: diff 记录不同字符数 两 ...

  4. 【Leetcode_easy】1071. Greatest Common Divisor of Strings

    problem 1071. Greatest Common Divisor of Strings solution class Solution { public: string gcdOfStrin ...

  5. 【Leetcode_easy】893. Groups of Special-Equivalent Strings

    problem 893. Groups of Special-Equivalent Strings 题意: 感觉参考代码也是有点问题的... 参考 1. Leetcode_easy_893. Grou ...

  6. 【LeetCode】205. Isomorphic Strings

    题目: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the c ...

  7. 【leetcode】415. Add Strings

    problem 415. Add Strings solution: class Solution { public: string addStrings(string num1, string nu ...

  8. 【LeetCode】43. Multiply Strings

    Multiply Strings Given two numbers represented as strings, return multiplication of the numbers as a ...

  9. 【SPOJ】MGLAR10 - Growing Strings

    Gene and Gina have a particular kind of farm. Instead of growing animals and vegetables, as it is us ...

随机推荐

  1. xml文件整理

    xml 97-2003 格式 \s*\n\s*\n\s*\n\s*\n\n(^个人补充信息.*)\n(.*)\n(^总成绩.*)$1$2\n$3(^个人补充信息.*)\n(.*)\n(.*)\n(^总 ...

  2. HttpClient SSL connection could not be established error

    系统从.net framework 升级到dotnet core2.1 原先工作正常的httpclient,会报SSL connection could not be established erro ...

  3. P3709 大爷的字符串题 脑子+莫队

    简化题意:区间众数出现次数??? 为什么?原因是,贪心的想,我们要划分成尽量少的严格递增序列,这样rp掉的最少. 设区间众数出现次数为 \(x\) ,那我们至少要分成 \(x\) 段严格上升序列. # ...

  4. C语言实现金字塔

    #include <stdio.h> int main(void) { int i=0, j =0, k= 0, line; printf("请输入金字塔的总行数:") ...

  5. cf 799E

    $des$有 $n$ 个物品,第 $i$ 个物品的价格是 $v_i$ ,有两个人,每个人都喜欢 $n$ 个物品中的一些物品.要求选出正好 $m$ 个物品,满足选出的物品中至少有 $k$ 个物品被第一个 ...

  6. 割点 —— Tarjan 算法

    由于对于这一块掌握的十分不好,所以在昨天做题的过程中一直困扰着我,好不容易搞懂了,写个小总结吧 qwq~ 割点 概念 在无向连通图中,如果将其中一个点以及所有连接该点的边去掉,图就不再连通,那么这个点 ...

  7. AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)

    题意 n个点的树k种颜色,距离不超过2的点对需颜色不同,求方案数 Code(copy) #include<iostream> #include<cstdio> #include ...

  8. [Linux] scp指令用法

    scp 指令用法 # scp usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [ ...

  9. webpack4-用之初体验

    众所周知,webpack进入第4个大版本已经有2个月的时间了,而且webpack团队升级更新的速度也是非常的惊人 在写下如下内容的时候webpack已经出到了4.6的版本了,剑指5.0应该是指日可待了 ...

  10. java实现获取当前年、月、日 、小时 、分钟、 秒、 毫秒

    转载 : https://blog.csdn.net/qq_36652619/article/details/85621020 package com.app.test; import java.te ...