上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 29 下一页

2018年2月11日

leetcode 389. Find the Difference

摘要: 注意,两个字符串顺序可以是乱的。 两种思路: 直接双哈希。异或。 阅读全文

posted @ 2018-02-11 11:15 willaty 阅读(166) 评论(0) 推荐(0) 编辑

leetcode 387. First Unique Character in a String

摘要: 哈希存索引,再遍历即可。 阅读全文

posted @ 2018-02-11 10:58 willaty 阅读(139) 评论(0) 推荐(0) 编辑

leetcode 383. Ransom Note

摘要: 用magazine中的字母拼接处ransomNote,都是小写。 对magazine的字母哈希,保存出现的次数,再用ransomNote遍历减小。 这里有两个注意的点。 1.一开始用unordered_map,居然比直接遍历还慢。 2.这里优化了一下,不直接对magazine全哈希,需要才哈希,避免 阅读全文

posted @ 2018-02-11 10:16 willaty 阅读(111) 评论(0) 推荐(0) 编辑

2018年2月9日

leetcode 383. Ransom Note

摘要: bool canConstruct(string ransomNote, string magazine) { unordered_map m; for (auto i : magazine) m[i]++; for (auto i : ransomNote) { if (m... 阅读全文

posted @ 2018-02-09 18:36 willaty 阅读(70) 评论(0) 推荐(0) 编辑

leetcode 374. Guess Number Higher or Lower

摘要: 二分。 阅读全文

posted @ 2018-02-09 18:25 willaty 阅读(82) 评论(0) 推荐(0) 编辑

leetcode 371. Sum of Two Integers

摘要: 异或其实是无进位加法,与取进位。 阅读全文

posted @ 2018-02-09 18:15 willaty 阅读(78) 评论(0) 推荐(0) 编辑

leetcode 367. Valid Perfect Square

摘要: 二分。 阅读全文

posted @ 2018-02-09 16:26 willaty 阅读(86) 评论(0) 推荐(0) 编辑

leetcode 350. Intersection of Two Arrays II

摘要: 两个哈希。 阅读全文

posted @ 2018-02-09 13:03 willaty 阅读(132) 评论(0) 推荐(0) 编辑

leetcode 349. Intersection of Two Arrays

摘要: 找出两个数组相同的元素。返回相同的元素集合即可。 两个思路: 1. 先将num1转为集合set1(去重),再遍历num2,查找set1中有没有出现。 2. 哈希,用两个unordered_map<int, bool>,再遍历即可。 这里用方法2: 阅读全文

posted @ 2018-02-09 12:14 willaty 阅读(97) 评论(0) 推荐(0) 编辑

2018年2月8日

leetcode 345. Reverse Vowels of a String

摘要: string reverseVowels(string s) { for (int i = 0, j = s.size() - 1; i < j;) { bool l = isVowels(s[i]); bool r = isVowels(s[j]); if (l && r) ... 阅读全文

posted @ 2018-02-08 15:45 willaty 阅读(100) 评论(0) 推荐(0) 编辑

上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 29 下一页

导航