leetcode刷题,总结,记录,备忘 383
来源:互联网 发布:阿里云数据盘扩容 编辑:程序博客网 时间:2024/06/15 04:40
leetcode383 Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; otherwise, it will return false.
Each letter in the magazine string can only be used once in your ransom note.
Note:
You may assume that both strings contain only lowercase letters.
canConstruct("a", "b") -> falsecanConstruct("aa", "ab") -> falsecanConstruct("aa", "aab") -> true遍历第一个字符串,将每个字符在第二个字符串中查找没有的话就返回错,找到的话就继续并在第二个字符串中将这个字符删除掉,继续遍历。
class Solution {public: bool canConstruct(string ransomNote, string magazine) { for (int i = 0; i < ransomNote.size(); ++i) { char c = ransomNote[i]; int pos; if ((pos = magazine.find(c)) == string::npos) { return false; } magazine.erase(pos, 1); } return true; }};
0 0
- leetcode刷题,总结,记录,备忘 383
- leetcode刷题。总结,记录,备忘 104
- leetcode刷题。总结,记录,备忘 100
- leetcode刷题。总结,记录,备忘 191
- leetcode刷题。总结,记录,备忘。168
- leetcode刷题, 总结,记录,备忘 171
- leetcode刷题 ,总结,记录,备忘。144
- leetcode刷题,总结,记录, 备忘 141
- leetcode刷题,总结,记录,备忘。116
- leetcode刷题,总结,记录,备忘。96
- leetcode刷题。记录,总结,备忘。217
- leetcode 刷题, 总结,记录,备忘 35
- leetcode刷题,总结,记录,备忘 226
- leetcode刷题,总结,记录,备忘 169
- leetcode刷题,总结,记录,备忘137
- leetcode刷题,总结,记录,备忘83
- leetcode刷题,总结,记录,备忘70
- leetcode刷题,总结,记录,备忘 108
- 短信验证码倒计时的实现
- android sdk启动报错error: could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037
- Leetcode 303. Range Sum Query - Immutable (Easy) (cpp)
- 【Linux开发】【Qt开发】QT 同时支持鼠标和触摸屏
- .net中URL重写
- leetcode刷题,总结,记录,备忘 383
- 使用ThreadLocal准确找到操作线程的对象
- 操蛋的博客我也是醉了,绑定账号爆炸了。
- Caffe学习:Blobs, Layers, and Nets
- NOIP2012 提高组 复赛 day1 vigenere vigenere密码
- svn在commit的错误信息:is scheduled for addition, but is missing
- 欢迎使用CSDN-markdown编辑器
- React-Native学习指南
- 二部图最大匹配--匈牙利算法