leetcode整理 Math
StudyCoder
这个作者很懒,什么都没留下…
展开
-
231. Power of Two
题目:Given an integer, write a function to determine if it is a power of two.题意:给定一个整数,写一个程序检测该整数是否是2的幂。思路一:最直接的方法就是不停地除以2,看最后的余数是否为1,要注意考虑输入是负数和0的情况。代码:递归版:8msclass Solution {转载 2016-06-18 15:59:15 · 181 阅读 · 0 评论 -
202. Happy Number
题目:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of th转载 2016-05-27 10:19:27 · 251 阅读 · 0 评论 -
204. Count Primes
题目:Description:Count the number of prime numbers less than a non-negative number, n.题意:统计小于非负整数n的素数的个数,素数不能被比它小的整数整除。思路:解题思路入提示二所示,埃拉托斯特尼筛法Sieve of Eratosthenes中,算法过程如下图所示,我们从2开始转载 2016-05-27 08:56:25 · 222 阅读 · 0 评论 -
263. Ugly Number
题目:Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not转载 2016-06-18 13:28:13 · 173 阅读 · 0 评论 -
258. Add Digits
题目:Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2转载 2016-06-18 12:42:14 · 253 阅读 · 0 评论 -
8. String to Integer (atoi)
题目:Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible转载 2016-06-18 10:49:24 · 219 阅读 · 0 评论 -
326. Power of Three
题目:Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?题意:给定一个整数,写一个程序检测该整数是否是3的幂。思路一:转载:http转载 2016-06-18 10:06:58 · 232 阅读 · 0 评论 -
9. Palindrome Number
题目: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 converting the integer to转载 2016-06-17 10:42:51 · 198 阅读 · 0 评论 -
223. Rectangle Area
题目:Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that转载 2016-06-17 09:52:24 · 191 阅读 · 0 评论 -
171. Excel Sheet Column Number
题目:Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3转载 2016-06-17 09:38:03 · 277 阅读 · 0 评论 -
7. Reverse Integer
题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321 题意:反向整数的位数。思路:将整数由低位到高位取出,再构成整数,用一个long long类型的整数存储转换之后的值来存储转换之后过大的值,之后对转换后的值进行判断是否溢出转载 2016-06-16 09:18:07 · 163 阅读 · 0 评论 -
168. Excel Sheet Column Title
题目:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB转载 2016-06-16 22:28:34 · 273 阅读 · 0 评论 -
172. Factorial Trailing Zeroes
题目:Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.题意:给定一个整数n,返回n!(n的阶乘)数字中的后缀0的个数。note:你的解法应该满足对数时间复杂度。转载 2016-06-18 14:44:46 · 247 阅读 · 0 评论