Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit db84840

Browse files
添加预判断长度的代码
在magazine中字符存入数组前,预先判断ransomNote和magazine的相对长度,进行处理。
1 parent 6b8b912 commit db84840

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

‎problems/0383.赎金信.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class Solution {
8484
public:
8585
bool canConstruct(string ransomNote, string magazine) {
8686
int record[26] = {0};
87+
//add
88+
if (ransomNote.size() > magazine.size()) {
89+
return false;
90+
}
8791
for (int i = 0; i < magazine.length(); i++) {
8892
// 通过recode数据记录 magazine里各个字符出现次数
8993
record[magazine[i]-'a'] ++;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /