摘要: Longest Substring Without Repeating Characters:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "... 阅读全文
posted @ 2016-03-08 19:55 Lewisr 阅读(156) 评论(0) 推荐(0) 编辑
摘要: Longest Palindromic Substring:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substr... 阅读全文
posted @ 2016-03-08 19:47 Lewisr 阅读(104) 评论(0) 推荐(0) 编辑
摘要: Permutation Sequence:The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3): "123" "132"... 阅读全文
posted @ 2016-03-06 19:38 Lewisr 阅读(248) 评论(0) 推荐(0) 编辑
摘要: Pow(x,n):Implement pow(x, n). 题意:实现pow(x,n)函数。 思路:采用递归的方式,进行计算,注意判断n的值的正负。 代码: public class Solution { public double myPow(double x, int n) { if(n<0){ return 1.0/power(x,-n); ... 阅读全文
posted @ 2016-03-06 19:31 Lewisr 阅读(202) 评论(0) 推荐(0) 编辑
摘要: Sqrt(x):Implement int sqrt(int x).Compute and return the square root of x. 题意:实现开方函数。 思路:采用二分查找的方式进行,判断。 代码: ublic class Solution { public int mySqrt(int x) { if(x>1); if(mid==... 阅读全文
posted @ 2016-03-06 19:28 Lewisr 阅读(171) 评论(0) 推荐(0) 编辑
摘要: Super Ugly Number: Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4... 阅读全文
posted @ 2016-03-06 19:24 Lewisr 阅读(315) 评论(0) 推荐(0) 编辑
摘要: 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) 编辑