Leetcode 383. Ransom Note (Easy) (cpp)
2016-08-20 12:06
344 查看
Leetcode 383. Ransom Note (Easy) (cpp)
Tag: String
Difficulty: Easy
/*
383. Ransom Note (Easy)
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") -> false
canConstruct("aa", "ab") -> false
canConstruct("aa", "aab") -> true
*/
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
for (auto cha_r : ransomNote) {
auto cha_m = magazine.find(cha_r);
if (cha_m == string::npos) return false;
magazine.erase(cha_m, 1);
}
return true;
}
};
Tag: String
Difficulty: Easy
/*
383. Ransom Note (Easy)
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") -> false
canConstruct("aa", "ab") -> false
canConstruct("aa", "aab") -> true
*/
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
for (auto cha_r : ransomNote) {
auto cha_m = magazine.find(cha_r);
if (cha_m == string::npos) return false;
magazine.erase(cha_m, 1);
}
return true;
}
};
相关文章推荐
- LeetCode-Easy部分中标签为String 383. Ransom Note
- LeetCode解题报告 383. Ransom Note [easy]
- 383. Ransom Note 难度:easy
- leetcode 383. Ransom Note HashMap 统计字符 + HashMap
- leetCode 383. Ransom Note 字符串
- leetcode 383. Ransom Note
- Leetcode 219. Contains Duplicate II (Easy) (cpp)
- Leetcode 290. Word Pattern (Easy) (cpp)
- LeetCode-383. Ransom Note (Java)
- Leetcode 171. Excel Sheet Column Number (Easy) (cpp)
- LeetCode-383. Ransom Note
- Leetcode 70. Climbing Stairs (Easy) (cpp)
- Leetcode 383. Ransom Note 构造字符串 解题报告
- 【LeetCode】 383. Ransom Note
- LeetCode笔记:383. Ransom Note
- [Leetcode] 383. Ransom Note 解题报告
- Leetcode 397. Integer Replacement (Easy) (cpp)
- Leetcode - String - 383. Ransom Note(水题)
- Leetcode 21. Merge Two Sorted Lists (Easy) (cpp)
- Leetcode 13. Roman to Integer (Easy) (cpp)