LeetCode题解之Happy Number】的更多相关文章

前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of c…
我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这个是书的地址:https://hk029.gitbooks.io/leetbook/ 009. Palindrome Number[E] 问题: Determine whether an integer is a palindrome. Do this without extra space. 思路 这里说不…
9. Palindrome Number 题目: Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the…
1.题目描述 2.题目分析 根据 happy number 的 性质,如果循环7次还没有到达 1,则这个数不是happy number . 3.代码 bool isHappy(int n) { ) return true; int result = n; ; do{ vector<int> rv = splitnum( result ); result = ; for(auto i: rv){ result += i*i; } count++; ){ return false; } } );…
1.题目描述 2. 将整数值转换为string  ,然后排序. 3.代码 string largestNumber(vector<int>& nums) { vector<string> s; for( auto n : nums){ s.push_back(to_string(n)); } sort( begin(s), end(s) , [](string &s1 , string s2){ return s1 + s2 < s2 + s1;}); str…
1.题目描述 2.问题分析 将数值转换为二进制,然后将前面的 0 去掉,再遍历一边二进制字符串,对每个字符和其后部的字符进行比较. 3.代码 bool hasAlternatingBits(int n) { ) return true; bitset<> b(n) ; string s = b.to_string() ; string::iterator it = s.begin() ; while( it != s.end() ){ ' )break; ++it; } s.assign(it…
1.题目描述 2.分析 3.代码 int singleNumber(vector<int>& nums) { map<int,int> m; for( vector<int>::iterator p = nums.begin() ; p != nums.end() ; ++p ) { m[*p]++; } ; i < nums.size() ; i++ ) { ) return nums[i]; } }…
1.题目描述 2.题目分析 将 [ 0 , n ]之间的整数放到 n 个元素的数组中去,必然缺失一个元素.在一次遍历中,将元素n[i] 放到 n[ n[i] ] ,位置.最后检查元素值和下标不相等的情况. 3.代码 int missingNumber(vector<int>& nums) { ) ; ; i < nums.size() ; i++ ) { if( nums[i] != i && nums[i] < nums.size() ){ swap( n…
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - Leetcode 414. Third Maximum Number题解 在线提交: https://leetcode-cn.com/problems/third-maximum-number 题目描述 414. 第三大的数 给定一个非空数组,返回此数组中第三大的数.如果不存在,则返回数组中最大的数.…
前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out no…