
Leetcode
文章平均质量分 70
店小不2
这个作者很懒,什么都没留下…
展开
-
Leetcode: Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2014-08-30 11:53:19 · 655 阅读 · 0 评论 -
Leetcode: Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on原创 2014-09-05 04:07:54 · 641 阅读 · 0 评论 -
Leetcode: Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may原创 2014-09-05 05:35:45 · 497 阅读 · 0 评论 -
Leetcode: Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c原创 2014-09-18 14:17:18 · 494 阅读 · 0 评论 -
Leetcode: String to Integer
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2014-09-19 06:28:46 · 507 阅读 · 0 评论 -
Leetcode: Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from原创 2014-09-19 05:41:42 · 367 阅读 · 0 评论 -
Leetcode: Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti原创 2014-09-19 14:51:05 · 473 阅读 · 0 评论 -
Leetcode: Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Clarification:What constitutes a word?A sequence of non-spac原创 2014-09-17 07:07:26 · 694 阅读 · 0 评论 -
Leetcode: 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.原创 2014-09-20 05:27:44 · 436 阅读 · 0 评论 -
Leetcode: Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.原创 2014-09-20 07:30:28 · 496 阅读 · 0 评论 -
Leetcode: 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 [4,−1,2,1] ha原创 2014-09-09 02:09:18 · 406 阅读 · 0 评论 -
Leetcode: Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2014-09-20 14:39:22 · 455 阅读 · 0 评论 -
Leetcode: Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin原创 2014-09-20 13:39:43 · 470 阅读 · 0 评论 -
Leetcode: 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact原创 2014-09-09 12:30:44 · 374 阅读 · 0 评论 -
Leetcode: Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy t原创 2014-08-26 04:58:02 · 482 阅读 · 0 评论 -
Leetcode: Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left原创 2014-09-21 13:34:52 · 723 阅读 · 0 评论 -
Leetcode: 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 substring.原创 2014-09-21 06:27:05 · 487 阅读 · 0 评论 -
Leetcode: 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c原创 2014-09-09 11:44:17 · 456 阅读 · 0 评论 -
Leetcode: Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).原创 2014-09-21 12:45:32 · 525 阅读 · 0 评论 -
Leetcode: Remove Duplicates from Sorted Array I and II
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原创 2014-09-21 05:26:44 · 467 阅读 · 0 评论 -
Leetcode: Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * public原创 2014-09-21 11:08:36 · 510 阅读 · 0 评论 -
Leetcode: Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]原创 2014-09-21 17:22:00 · 627 阅读 · 0 评论 -
Leetcode: Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2014-09-22 07:05:07 · 404 阅读 · 0 评论 -
Leetcode: 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Element原创 2014-09-10 09:53:47 · 397 阅读 · 0 评论 -
Leetcode: Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2014-09-22 06:29:10 · 492 阅读 · 0 评论 -
Leetcode: 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""213""231""3原创 2014-08-27 07:27:48 · 470 阅读 · 0 评论 -
Leetcode: Search Insert Position
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.原创 2014-09-11 15:00:40 · 736 阅读 · 0 评论 -
Leetcode: Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found原创 2014-09-12 07:18:25 · 494 阅读 · 0 评论 -
Leetcode: Sort Colors
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原创 2014-09-10 14:30:44 · 460 阅读 · 0 评论 -
Leetcode: Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible原创 2014-08-29 09:30:28 · 546 阅读 · 0 评论 -
Leetcode: Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur原创 2014-09-12 13:59:21 · 429 阅读 · 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原创 2014-08-30 08:00:37 · 543 阅读 · 0 评论 -
Leetcode: Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?/** * Definition for singly-l原创 2014-09-26 06:52:20 · 492 阅读 · 0 评论 -
Leetcode: Sort List
Sort a linked list in O(n log n) time using constant space complexity.原创 2014-09-26 08:22:37 · 406 阅读 · 0 评论 -
Leetcode: Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each原创 2014-09-16 09:59:38 · 477 阅读 · 0 评论 -
Leetcode: Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without原创 2014-08-30 09:00:26 · 559 阅读 · 0 评论 -
Leetcode: Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?原创 2014-09-26 06:18:45 · 406 阅读 · 0 评论 -
Leetcode: Single Number III (Single Number扩展)
Given an array of integers, every原创 2014-09-04 05:32:31 · 1913 阅读 · 0 评论 -
Leetcode: Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.原创 2014-09-17 13:24:33 · 476 阅读 · 0 评论 -
Leetcode: Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solutio原创 2014-09-28 12:04:21 · 355 阅读 · 0 评论