Just for fun

# 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") -> false
canConstruct("aa", "ab") -> false
canConstruct("aa", "aab") -> true


class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
int pool[26] = {0};
for (char c : magazine) {
pool[c-'a']++;
}
for (char c : ransomNote) {
if (pool[c-'a'] > 0) {
pool[c-'a']--;
} else {
return false;
}
}
return true;
}
};

#### LeetCode:383 Ransom Note

2016-08-11 20:54:51

#### 【LeetCode】383 Ransom Note（java）

2016-08-17 17:35:30

#### [leetcode] 383. Ransom Note

2016-08-11 15:52:41

#### Leetcode383. Ransom Note

2016-11-26 22:25:47

#### LeetCode383. Ransom Note

2016-08-17 23:50:51

#### leetcode383. Ransom Note

2017-03-29 20:52:14

#### Leetcode - String - 383. Ransom Note（水题）

2016-08-16 12:03:34

#### 关于LeetCode中Ransom Note一题的理解

2016-08-29 17:20:40

#### 【Leetcode】Ransom Note

2016-08-12 07:31:31

#### LeetCode 383. Ransom Note

2016-08-12 15:52:54