mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-13 22:35:09 +08:00
添加预判断长度的代码
在magazine中字符存入数组前,预先判断ransomNote和magazine的相对长度,进行处理。
This commit is contained in:
@ -84,6 +84,10 @@ class Solution {
|
||||
public:
|
||||
bool canConstruct(string ransomNote, string magazine) {
|
||||
int record[26] = {0};
|
||||
//add
|
||||
if (ransomNote.size() > magazine.size()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < magazine.length(); i++) {
|
||||
// 通过recode数据记录 magazine里各个字符出现次数
|
||||
record[magazine[i]-'a'] ++;
|
||||
|
Reference in New Issue
Block a user