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. 洛谷 P2827 蚯蚓 题解

    每日一题 day32 打卡 Analysis 我们可以想一下,对于每一秒除了被切的哪一个所有的蚯蚓都增长Q米,我们来维护3个队列,队列1表示最开始的蚯蚓,队列2表示每一次被切的蚯蚓被分开的较长的那一部 ...

  2. Kubernetes 学习24 helm入门

    一.概述 1.我们此前在使用kubernetes中,无论我们使用无状态的应用程序,比如myapp,nginx.以及有状态的tomcat,redis,etcd,...等等,他们部署在k8s之上会有这样的 ...

  3. Luogu P3810 【模板】三维偏序(陌上花开) CDQ分治 树状数组

    https://www.luogu.org/problemnew/show/P3810 复习板子,重要的题就真的要写三遍???之前写过一篇博客了,不过之前写的那个板子的sort用的规则真是沙雕 #in ...

  4. 猴猴吃香蕉 背包DP

    猴猴吃香蕉 背包DP \(D\)次询问,第\(i\)次询问,每次有\(n_i\)个带权香蕉,问有多少方案使香蕉之积为\(k_i\),对结果取模\(1000000007\) \(n\le 10^3,k\ ...

  5. Chrome教程(二)使用ChromeDevTools命令菜单运行命令

    1.模拟移动设备 点击 Toggle Device Toolbar可以打开用于模拟移动设备视口的界面. 2.限制网络流量和 CPU 占用率 要限制网络流量和 CPU 占用率,请从 Throttle 列 ...

  6. php unset

    说明:unset ( mixed $var [, mixed $... ] ) : void unset() 销毁指定的变量. unset() 在函数中的行为会依赖于想要销毁的变量的类型而有所不同. ...

  7. 设置虚拟机ip地址

    当我们在linux中输入命令ifconfig来查找ip地址的时候,可能会出现只有ipv6,而没有inet的情况,这时需要自己设定,有两种方式可供选择: 1,命令 ifconfig 设备名(如eth0) ...

  8. 安卓开发实战之app之版本更新升级(DownloadManager和http下载)完整实现

    转载: https://blog.csdn.net/u013278099/article/details/52692008 前言 本文将讲解app的升级与更新.一般而言用户使用App的时候升级提醒有两 ...

  9. HTML5+和MUI页面操作

    最近总是碰到针对页面的一些操作,以下是针对webview的一些简单方法以及个人理解.更多详尽的内容请参考标准文档:http://www.html5plus.org/doc/zh_cn/webview. ...

  10. 关于postman与shiro权限验证问题

    作为一个java的开发小白 , 写完一个web方法测试是必不可少的 , 只有测试号没问题的方法给别人时 ,别人才不知道你是小白 , 要不然很尴尬的 .新手入坑的测试工具是postman .这个工具用起 ...