![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode-Math
peanwang
这个作者很懒,什么都没留下…
展开
-
LeeetCode 7 . Reverse Integer
7. Reverse Integer class Solution { public: int reverse(int x) { bool flag = x>=0; x = flag?x:-x; long long reverse_x = 0; do{ reverse_x = reverse_x*...原创 2018-11-15 22:02:46 · 136 阅读 · 0 评论 -
LeetCode 8 String to Integer(atoi)
8 String to Integer(atoi) class Solution { public: int myAtoi(string str) { int i=0,len = str.size(); long long result=0; while(i<len && str[i]==' ') ...原创 2018-11-16 14:16:38 · 108 阅读 · 0 评论 -
LeetCode 231. Power of Two
231. Power of Two class Solution { public: bool isPowerOfTwo(int n) { if(n==0) return false; else if(n == 1) return true; else return is...原创 2018-11-16 14:36:07 · 103 阅读 · 0 评论 -
LeetCode 191. Number of 1 Bits
191. Number of 1 Bits class Solution { public: int hammingWeight(uint32_t n) { const int array[]={0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4}; int count=0; uint32_t m = n>>16; ...原创 2018-11-25 16:53:03 · 71 阅读 · 0 评论 -
LeetCode 202. Happy Number
202. Happy Number class Solution { public: bool isHappy(int n) { unordered_map<int,bool> show; while(true){ int result = 0; while(n){ ...原创 2018-11-30 14:18:56 · 97 阅读 · 0 评论 -
LeetCode 258. Add Digits
258. Add Digits /* using recursion */ class Solution { public: int addDigits(int num) { if(num<10) return num; else{ int result = 0; while(nu...原创 2018-11-30 14:20:22 · 89 阅读 · 0 评论