归档: 2016/7

记录点滴,修炼自己。
0

leetcode [#92]

题目 Reverse a linked list from position m to n. Do it in-place and in one-pass. Example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL. Example:Giv

0

leetcode [#9]

题目 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 string, note

0

leetcode [#88]

题目 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 additi

0

leetcode [#86]

题目 Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each o

0

leetcode [#82]

题目 Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Example:Given 1->2->3->3->4->4->5, return 1->2-

0

leetcode [#83]

题目 Given a sorted linked list, delete all duplicates such that each element appear only once. Example:Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. 解决方案

0

leetcode [#8]

题目 Implement atoi to convert a string to an integer. HintCarefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cas

0

leetcode [#75]

题目 Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers

0

leetcode [#7]

题目 Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 解决方案1234567891011public class Solution { public int reverse(int x) { String s = Str

0

leetcode [#67]

题目 Given two binary strings, return their sum (also a binary string). Examplea = “11”b = “1”Return “100”. 解决方案123456789101112131415161718192021222324252627282930313233343536373839404142434445464748

0

leetcode [#66]

题目 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. 解决方案1234567891011121

0

leetcode [#62]

题目 A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the

0

leetcode [#58]

题目 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. ExampleGiven s = “H

0

leetcode [#53]

题目 Find the contiguous subarray within an array (containing at least one number) which has the largest sum. Examplegiven the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] has the l

0

leetcode [#6]

题目 The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) 123P A H NA P L S

0

leetcode [#448]

题目 Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Coul

0

leetcode [#463]

题目 You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is complet

0

leetcode [#415]

题目 Given n points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of th

0

leetcode [#438]

题目 Given a string s and a non-empty string p, find all the start indices of p’s anagrams in s.Strings consists of lowercase English letters only and the length of both strings s and p will not be lar

0

leetcode [#409]

题目 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

0

leetcode [#414]

题目 Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example1:Input: [3, 2, 1]

0

leetcode [#415]

题目 Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < 5100. Both num1 and num2 contains only digits 0

0

leetcode [#400]

题目 Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … Example1:Input:3 Output:3 Example2:Input:11 Output:0 Explanation:The 11th digit of the sequence 1, 2, 3, 4,

0

leetcode [#396]

题目 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: F(k) =

0

leetcode [#394]

题目 Given an encoded string, return it’s decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is

0

leetcode [#383]

题目 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 constructed from the magazines

0

leetcode [#389]

题目 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 ad

0

leetcode [#374]

题目 We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I’ll tell you whether the number is higher

0

leetcode [#36]

题目 解决方案12 注意事项 以下方法是错误的:12345678910111213141516171819202122import java.util.HashSet;public class Solution { public boolean isValidSudoku(char[][] board) { for(int i = 0; i <

0

leetcode [#38]

题目 The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, … 1 is read off as “one 1” or 11.11 is read off as “two 1s” or 21.21 is read off as “one 2, the

0

leetcode [#350]

题目 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 many times a

0

leetcode [#35]

题目 Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array

0

leetcode [#349]

题目 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. The result can b

0

leetcode [#344]

题目 Write a function that takes a string as input and reverse only the vowels of a string. Example:Given s = “hello”, return “holle”.Given s = “leetcode”, return “leotcede”. Note:The vowels does not i

0

leetcode [#344]

题目 Write a function that takes a string as input and returns the string reversed. Example:Given s = “hello”, return “olleh”. 解决方案1234567public class Solution { public String reverseString(S

0

leetcode [#299]

题目 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

0

leetcode [#341]

题目 Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list – whose elements may also be integers or other lists. Example:Given the list [[1,

0

leetcode [#326]

题目 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? 解决方案12345678910111213public class Solution { publ

0

leetcode [#290]

题目 Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str. Exam

0

leetcode [#292]

题目 You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be

0

leetcode [#283]

题目 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. Example:given nums = [0, 1, 0, 3, 12], after calling your func

0

leetcode [#278]

题目 You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on

0

leetcode [#28]

题目 Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 解决方案123456789101112131415161718192021222324252627282930public class

0

leetcode [#263]

题目 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. ExampleFor example, 6, 8 are ugly while 14 is not ugl

0

leetcode [#268]

题目 Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array. For example: Given nums = [0, 1, 3] return 2. NoteYour algorithm should run in l

0

leetcode [#26]

题目 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 wit

0

leetcode [#27]

题目 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. Th