随笔分类 -  LeetCode(Java)

摘要: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 阅读(158) 评论(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 阅读(110) 评论(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 阅读(252) 评论(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 阅读(208) 评论(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 阅读(174) 评论(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 阅读(320) 评论(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 阅读(144) 评论(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 阅读(114) 评论(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 阅读(121) 评论(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 阅读(127) 评论(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 阅读(116) 评论(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 阅读(126) 评论(0) 推荐(0)
摘要:Binary Tree Level Order Traversal:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, ... 阅读全文
posted @ 2016-03-01 19:19 Lewisr 阅读(139) 评论(0) 推荐(0)
摘要:Same Tree:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 题意:判断两棵... 阅读全文
posted @ 2016-03-01 19:15 Lewisr 阅读(121) 评论(0) 推荐(0)
摘要:Symmetric Tree:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But th... 阅读全文
posted @ 2016-03-01 19:04 Lewisr 阅读(128) 评论(0) 推荐(0)
摘要:Balanced Binary Tree:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every... 阅读全文
posted @ 2016-03-01 18:58 Lewisr 阅读(132) 评论(0) 推荐(0)
摘要:Maximum Subarray: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [... 阅读全文
posted @ 2016-02-19 14:30 Lewisr 阅读(108) 评论(0) 推荐(0)
摘要:Majority Element II:Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space. 题意:找出给定数组中出现次数多于数组长度三分之一的元素 思路:根... 阅读全文
posted @ 2016-02-19 14:15 Lewisr 阅读(148) 评论(0) 推荐(0)
摘要:Word Search:Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, 阅读全文
posted @ 2016-02-19 14:07 Lewisr 阅读(137) 评论(0) 推荐(0)
摘要:Find Peak Element:A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple ... 阅读全文
posted @ 2016-01-26 20:33 Lewisr 阅读(120) 评论(0) 推荐(0)