翻译写一个算法来决定一个数是否是“开心”的。开心数是被如下步骤所定义的数:从所有正整数开始,用其每个数字的平方和来替代这个数,不断重复这个过程直到最后的结果为1(此时它就停止了),或者它在一个不包含1的周期内无限循环。这些在这个过程中以1结尾的数就是开心数。例如:19是开心数。12+92=821^2 + 9^2 = 82
82+22=688^2 + 2^2 = 68
62+82=1006^2 +...
分类:
移动开发 时间:
2016-01-19 12:47:33
阅读次数:
275
map,管理数组,存储“关键字-值”set,简单集合,存储“关键字”四个关联容器的头文件map、set、unordered_map、unordered_set关联容器有8种,特点如下:每个容器都是set或者map分为允许关键字重复(multi)和不允许关键字重复顺序保存和无序保存(unordered...
分类:
其他好文 时间:
2015-11-24 21:16:36
阅读次数:
187
DFS with pruning. The thought flow: for each char, we have 2 choices: pick or not - then DFS.class Solution { int len; unordered_set rec; vector ...
分类:
其他好文 时间:
2015-11-05 07:37:51
阅读次数:
263
题目:
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
For example,
Given [100, 4, 200, 1, 3, 2],
The longest consecutive elements sequence is [1,...
分类:
其他好文 时间:
2015-11-04 11:32:42
阅读次数:
181
A typical Union-Find one. I'm using a kinda Union-Find solution here. Some boiler-plate code - yeah I know.class Solution { unordered_set hs; // st...
分类:
其他好文 时间:
2015-10-22 14:08:42
阅读次数:
169
Another topological sorting problem. Note: the DFS one is like a 'post-order' traversal.class Solution { unordered_map> g; unordered_set visited...
分类:
其他好文 时间:
2015-08-25 14:10:04
阅读次数:
189
DFS to check cyclic. Please note some details.class Solution{ unordered_map> g; unordered_set visited; bool go(int i, int p) // true - cy...
分类:
其他好文 时间:
2015-08-21 14:59:18
阅读次数:
173
bool containsDuplicate(vector& nums) { return !(nums.size() == unordered_set(nums.cbegin(), nums.cend()).size());}
分类:
编程语言 时间:
2015-08-04 09:18:15
阅读次数:
117
转自:http://blog.csdn.net/truexf/article/details/17303263一、vectorvector采用一段连续的内存来存储其元素,向vector添加元素的时候,如果容量不足,vector便会重新malloc一段更大的内存,然后把原内存中的数据memcpy到新的...
分类:
编程语言 时间:
2015-07-31 10:14:40
阅读次数:
157
在 JSON 中,“Object” 是什么呢? json.org 有很好的解释:1 、An object is an unordered set of name/value pairs. 2、An object begins with { (left brace) and ends with } (...
分类:
Web程序 时间:
2015-06-12 13:14:24
阅读次数:
161