【Leetcode_easy】859. Buddy Strings
problem
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的更多相关文章
- 【LeetCode】859. Buddy Strings 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcod ...
- 【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 ...
- 859. Buddy Strings - LeetCode
Question 859. Buddy Strings Solution 题目大意: 两个字符串,其中一个字符串任意两个字符互换后与另一个字符串相等,只能互换一次 思路: diff 记录不同字符数 两 ...
- 【Leetcode_easy】1071. Greatest Common Divisor of Strings
problem 1071. Greatest Common Divisor of Strings solution class Solution { public: string gcdOfStrin ...
- 【Leetcode_easy】893. Groups of Special-Equivalent Strings
problem 893. Groups of Special-Equivalent Strings 题意: 感觉参考代码也是有点问题的... 参考 1. Leetcode_easy_893. Grou ...
- 【LeetCode】205. Isomorphic Strings
题目: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the c ...
- 【leetcode】415. Add Strings
problem 415. Add Strings solution: class Solution { public: string addStrings(string num1, string nu ...
- 【LeetCode】43. Multiply Strings
Multiply Strings Given two numbers represented as strings, return multiplication of the numbers as a ...
- 【SPOJ】MGLAR10 - Growing Strings
Gene and Gina have a particular kind of farm. Instead of growing animals and vegetables, as it is us ...
随机推荐
- 一.使用LDAP认证
作用:网络用户认证,用户集中管理 网络用户信息:LDAP服务器提供 本地用户信息:/etc/passwd /etc/shadow提供 LDAP服务器:虚拟机classroom LDAP ...
- poj 3735 稀疏矩阵矩阵快速幂
设人数为 $n$,构造 $(n + 1) \times (n + 1)$ 的矩阵 得花生:将改行的最后一列元素 $+ 1$ \begin{gather}\begin{bmatrix}1 & 0 ...
- 模板 - 数据结构 - 栈/Stack
普通的栈大家都会写,STL的栈据说默认实现方式是deque,没关系反正deque跑得飞快. 这里收录的是一些奇怪的栈,当然双栈实现的队列收录在队列里面. 对顶栈 众所周知,栈可以维护一系列前缀和,包括 ...
- js判断是不是在微信浏览器打开?
is_weixin:function(){ var ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/Mic ...
- OpenFOAM清理计算结果(只保留原始的0,system,constant)
原视频下载地址:https://yunpan.cn/cMpyLZq8sWQgq(提取码:a08b)
- localstorage 必知必会
做项目中发现localstorage在不同的域名下是不能相互访问的,于是找到了以下这篇文章,对localStorage做一个深入的了解 HTML API localstorage在浏览器的API有两个 ...
- 第10组 Alpha冲刺(1/6)
链接部分 队名:女生都队 组长博客: 博客链接 作业博客:博客链接 小组内容 史恩泽(组长) 过去两天完成了哪些任务 描述 了解了反馈机制的实现原理 确定好算法的框架 对接口的规范化进行学习 展示Gi ...
- ubuntu16.04安装python3.7
1.安装依赖包 sudo apt-get update sudo apt-get install build-essential python-dev python-setuptools python ...
- NGUI: Next-Gen UI 2018.3.0f
https://assetstore.unity.com/packages/tools/gui/ngui-next-gen-ui-2413 NGUI is a very powerful UI sys ...
- LSTM和双向LSTM讲解及实践
LSTM和双向LSTM讲解及实践 目录 RNN的长期依赖问题LSTM原理讲解双向LSTM原理讲解Keras实现LSTM和双向LSTM 一.RNN的长期依赖问题 在上篇文章中介绍的循环神经网络RNN在训 ...