Leetcode
quansjtu
这个作者很懒,什么都没留下…
展开
-
[Leetcode] Longest Palindrome 最长回文
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example "Aa" is not con原创 2016-10-06 15:44:49 · 252 阅读 · 0 评论 -
[Leetcode] Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution. Example: Given nums =原创 2016-09-19 14:20:20 · 190 阅读 · 0 评论 -
[Leetcode] Nth Digit
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n is positive and will fit within the range of a 32-bit signed integer (n 31). Example 1: Input原创 2016-09-19 13:55:38 · 480 阅读 · 0 评论 -
[Leetcode] Rotate Function
Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow:原创 2016-09-18 23:18:22 · 223 阅读 · 0 评论 -
[Leetcode] Reverse Bits
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010原创 2016-09-18 22:22:41 · 186 阅读 · 0 评论 -
[Leetcode] Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. public class Solution { public String longestCommonPrefix(String[] strs) { Arrays.sort(strs);原创 2016-09-18 22:03:22 · 195 阅读 · 0 评论 -
[转载]Longest Common Prefix 算法
Question: Write a function to find the longest common prefix string amongst an array of strings. Quick Navigation Solution Approach #1 (Horizontal scanning)Approach #2 (Vertical转载 2016-09-18 21:57:36 · 495 阅读 · 0 评论 -
[Leetcode] Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Note: A word is原创 2016-09-18 20:51:57 · 148 阅读 · 0 评论 -
[Leetcode] Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j]and the difference between i and j is at most k. p原创 2016-09-18 20:22:17 · 169 阅读 · 0 评论 -
[Leetcode] Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add原创 2016-09-18 12:12:06 · 174 阅读 · 0 评论 -
[Leetcode] Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 方法1:利用系统方法String.indexOf(),耗时6ms public class Solution { publ原创 2016-09-19 16:12:29 · 188 阅读 · 0 评论 -
[Leetcode] Integer Replacement
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2.If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number o原创 2016-09-20 18:12:38 · 191 阅读 · 0 评论 -
[Leetcode] Is Subsequence
Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) strin原创 2016-09-20 22:23:52 · 294 阅读 · 0 评论 -
[Leetcode] Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with原创 2016-09-29 14:05:03 · 205 阅读 · 0 评论 -
[Leetcode] Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory.原创 2016-09-29 13:18:31 · 268 阅读 · 0 评论 -
[Leetcode] Plus One
Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. 本题方法是从最后一位开始加进制位,个数加原创 2016-09-29 12:05:17 · 229 阅读 · 0 评论 -
[Leetcode] Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. /** * Definition f原创 2016-09-28 13:09:04 · 195 阅读 · 0 评论 -
[Leetcode] Single Number
Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2016-09-28 12:40:59 · 185 阅读 · 0 评论 -
[Leetcode] Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constru原创 2016-09-28 12:32:33 · 210 阅读 · 0 评论 -
[Leetcode] First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note:原创 2016-09-28 12:10:40 · 215 阅读 · 0 评论 -
[Leetcode] Convert a Number to Hexadecimal
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used. Note: All letters in hexadecimal (a-f) must be in lowercase.The hexade原创 2016-09-28 10:48:28 · 252 阅读 · 0 评论 -
[Leetcode] Find the Difference
Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at a random position. Find the letter that was原创 2016-09-20 23:10:17 · 191 阅读 · 0 评论 -
[Leetcode] Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2016-09-17 19:22:25 · 128 阅读 · 0 评论 -
[Leetcode] Isomorphic Strings
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with anot原创 2016-09-17 15:10:01 · 154 阅读 · 0 评论 -
[Leetcode] Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element原创 2016-09-16 17:24:46 · 162 阅读 · 0 评论 -
[Leetcode] Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element原创 2016-09-16 17:23:31 · 162 阅读 · 0 评论 -
[Leetcode] Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. Note: You may a原创 2016-09-15 22:45:14 · 175 阅读 · 0 评论 -
[Leetcode] Excel Sheet Column Number
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ...原创 2016-09-15 22:40:39 · 195 阅读 · 0 评论 -
[Leetcode] Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element in the result must be unique. T原创 2016-09-15 22:31:20 · 168 阅读 · 0 评论 -
[Leetcode] Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2016-09-15 16:25:48 · 211 阅读 · 0 评论 -
[Leetcode] Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3, 12], after calling you原创 2016-09-15 16:07:38 · 165 阅读 · 0 评论 -
[Leetcode] 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 has on原创 2016-09-15 16:01:45 · 172 阅读 · 0 评论 -
[Leetcode] Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. public class Solution { public int getSum(int a, in原创 2016-09-15 15:54:35 · 194 阅读 · 0 评论 -
[Leetcode] Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each element in the result should appear as ma原创 2016-09-16 17:25:44 · 159 阅读 · 0 评论 -
[Leetcode] 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? public class Solution { public boolean isPowerO原创 2016-09-16 17:27:00 · 165 阅读 · 0 评论 -
[Leetcode] Power of Two
Given an integer, write a function to determine if it is a power of two. Credits: Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases. public class So原创 2016-09-16 17:28:23 · 135 阅读 · 0 评论 -
[Leetcode] Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t原创 2016-09-16 17:49:17 · 161 阅读 · 0 评论 -
[Leetcode] House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2016-09-16 17:48:06 · 317 阅读 · 0 评论 -
[Leetcode] Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Given num = 16, return true. Given num = 5, return false. Follow up: Could you solve it without原创 2016-09-16 17:46:55 · 214 阅读 · 0 评论 -
[Leetcode] Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = "hello", return "holle". Example 2: Given s = "leetcode", return "leotcede". Note原创 2016-09-16 17:45:13 · 162 阅读 · 0 评论