码迷,mamicode.com
首页 >  
搜索关键字:unordered_set    ( 85个结果
[LeetCode] Contains Duplicate
A classic problem of hash set. The unordered_set of C++ is very suitable for this problem.The code is as follows and it should be quite self-explanato...
分类:其他好文   时间:2015-06-09 11:43:57    阅读次数:93
LeetCode "Contains Duplicate II"
Maintain a hashset with size of (K + 1)class Solution {public: bool containsNearbyDuplicate(vector& nums, int k) { unordered_set hs; ...
分类:其他好文   时间:2015-05-30 01:48:09    阅读次数:108
leetcode BFS
1. word ladder 1 class Solution 2 { 3 public: 4 int ladderLength(string beginWord, string endWord, unordered_set &wordDict) 5 { 6 queu...
分类:其他好文   时间:2015-05-09 23:32:41    阅读次数:133
LeetCode Happy Number
1 class Solution { 2 public: 3 bool isHappy(int n) { 4 int last = n; 5 6 unordered_set exist; 7 8 do { ...
分类:移动开发   时间:2015-04-23 01:51:28    阅读次数:136
LeetCode Word Ladder 找单词变换梯
题意:给出两个单词,以及一个set集合,当中是很多的单词。unordered_set是无序的集合,也就是说找的序列也是无序的了,是C++11的标准,可能得升级你的编译器版本了。要求找出一个从start到end这两个单词的变换序列。从start开始,每次可以变一个字母,且所变之后的单词必须在set中,...
分类:其他好文   时间:2015-03-30 20:52:17    阅读次数:124
LeetcodeOJ: Restore IP Addresses backtrack暴搜
1 class Solution { 2 public: 3 vector ret; 4 string src; 5 int len; 6 unordered_set added; 7 vector restoreIpAddresses(string...
分类:其他好文   时间:2015-02-18 12:57:59    阅读次数:190
Leetcode#127 Word Ladder
原题地址BFSWord Ladder II的简化版(参见这篇文章)由于只需要计算步数,所以简单许多。代码: 1 int ladderLength(string start, string end, unordered_set &dict) { 2 if (start == end) ...
分类:其他好文   时间:2015-01-30 19:18:24    阅读次数:128
Serializable unordered set
Serializable unordered set 可序列化的哈希表/*'''[[[[[[[[[[[[[[[ ]]]]]]]]]]]]]]][:::::::::::::: ...
分类:其他好文   时间:2015-01-29 23:47:42    阅读次数:165
Leetcode#139 Word Break
原题地址与Word Break II(参见这篇文章)相比,只需要判断是否可行,不需要构造解,简单一些。依然是动态规划。代码: 1 bool wordBreak(string s, unordered_set &dict) { 2 int maxLen = 0; 3 f...
分类:其他好文   时间:2015-01-28 12:46:20    阅读次数:150
Word Ladder
该题目考察的知识点是宽度优先搜索,宽度优先搜索可以用队列保存计算的中间变量。需要注意的是urordered_set,是哈希表实现,查找的效率很高。利用这个特点做题。具体实现的代码如下:class Solution {public: unordered_set data; queue> result;...
分类:其他好文   时间:2014-12-26 22:52:57    阅读次数:218
85条   上一页 1 ... 5 6 7 8 9 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!