摘要: Ugly Number II:Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of t... 阅读全文
posted @ 2016-03-05 19:56 Lewisr 阅读(140) 评论(0) 推荐(0) 编辑
摘要: Number of Digit One:Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in ... 阅读全文
posted @ 2016-03-05 19:53 Lewisr 阅读(104) 评论(0) 推荐(0) 编辑
摘要: Divide Two Integers:Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 题意:实现整数的除法,不能使用/运算 阅读全文
posted @ 2016-03-05 19:29 Lewisr 阅读(113) 评论(0) 推荐(0) 编辑
摘要: Count Primes:Count the number of prime numbers less than a non-negative number, n. 题意:求出小于n的数中质数的个数。 思路:可以先写出一个判断一个整数是否是质数的函数,然后在从1到n开始判断,但是通过不了,看了提示中的Sieve of Eratosthenes,可以根据它进行求解。 代码: public class... 阅读全文
posted @ 2016-03-05 19:24 Lewisr 阅读(120) 评论(0) 推荐(0) 编辑
摘要: Palindrome Number:Determine whether an integer is a palindrome. Do this without extra space. 题意:判断一个整数是否是回文数,且不可以使用额外的空间。 思路:首先负数不是回文数,然后每次取出数的最高位和最低位,进行判断。 代码: public class Solution { public bool... 阅读全文
posted @ 2016-03-05 19:15 Lewisr 阅读(114) 评论(0) 推荐(0) 编辑
摘要: Number of i Bits:Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer “11” has binary representa... 阅读全文
posted @ 2016-03-05 19:03 Lewisr 阅读(122) 评论(0) 推荐(0) 编辑