LeetCode专栏
文章平均质量分 52
这里是LeetCode的专栏,大部分采用java语言实现,少量采用c++
mlweixiao
这个作者很懒,什么都没留下…
展开
-
LeetCode 99 Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis原创 2014-08-29 20:06:12 · 609 阅读 · 1 评论 -
LeetCode 46 Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].原创 2014-08-28 14:31:02 · 1209 阅读 · 2 评论 -
LeetCode 45 Permutations
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].思原创 2014-08-28 14:20:56 · 1093 阅读 · 1 评论 -
LeetCode 30 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 o原创 2014-08-28 09:40:05 · 807 阅读 · 1 评论 -
LeetCode 44 Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i原创 2014-08-27 17:44:20 · 792 阅读 · 1 评论 -
LeetCode 54 Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if yo原创 2014-08-26 15:28:52 · 497 阅读 · 0 评论 -
LeetCode 34 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 in t原创 2014-08-27 11:15:18 · 703 阅读 · 1 评论 -
LeetCode 24 Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is原创 2014-08-18 21:30:48 · 515 阅读 · 0 评论 -
LeetCode 93 Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order原创 2014-08-17 19:19:08 · 511 阅读 · 0 评论 -
LeetCode 77 Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2014-08-14 22:03:42 · 593 阅读 · 0 评论 -
LeetCode 103 Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary原创 2014-08-14 16:11:53 · 676 阅读 · 0 评论 -
LeetCode 61 Unique Paths
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原创 2014-07-08 18:43:15 · 515 阅读 · 0 评论 -
LeetCode 35 Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2014-07-07 13:38:45 · 955 阅读 · 0 评论 -
leetcode 1 Two Sum
Given an array of integers,find two numbers such that they add up to a specific target number.The function twoSum shouldreturn indices of the two numbers such that they add up to the target, wherein原创 2014-05-06 22:02:50 · 458 阅读 · 0 评论 -
leetcode 2 MEDIAN OF TWO SORTED ARRAYS
There are two sorted arrays A and B of size mand n respectively. Find the median of the two sorted arrays. The overall runtime complexity should be O(log (m+n)).原创 2014-05-06 22:05:45 · 437 阅读 · 0 评论 -
leetcode 3 LONGEST SUBSTRING WITHOUT REPEATING CHARACTERS
Given astring, find the length of the longest substring without repeating characters.For example, the longest substring without repeating letters for"abcabcbb" is "abc", which the length is 3. For"bbb原创 2014-05-06 22:08:10 · 473 阅读 · 0 评论 -
leetcode 4 ADD TWO NUMBERS
Youare given two linked lists representing two non-negative numbers. The digitsare stored in reverse order and each of their nodes contain a single digit. Addthe two numbers and return it as a linke原创 2014-05-06 22:11:24 · 448 阅读 · 0 评论 -
leetcode 7 REVERSE INTEGER
Reversedigits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Haveyou thought about this?Here are some good questions to askbefore coding. Bonus points for you if you原创 2014-05-06 22:13:31 · 484 阅读 · 0 评论 -
leetcode 8 STRING TO INTEGER (ATOI)
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-05-06 22:16:20 · 433 阅读 · 0 评论 -
leetcode 9 Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.原创 2014-05-06 22:18:13 · 455 阅读 · 0 评论 -
leetcode 11 Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin原创 2014-05-06 22:36:01 · 635 阅读 · 0 评论 -
leetcode 12 Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: string intToRoman(int num) { string ans;原创 2014-05-06 22:39:24 · 722 阅读 · 0 评论 -
leetcode 13 Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.原创 2014-05-06 22:41:23 · 549 阅读 · 0 评论 -
leetcode 15 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-05-06 22:42:56 · 444 阅读 · 0 评论 -
leetcode 16 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-05-06 22:44:09 · 420 阅读 · 0 评论 -
leetcode 19 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-05-06 22:48:44 · 371 阅读 · 0 评论 -
leetcode 20 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原创 2014-05-06 22:50:00 · 342 阅读 · 0 评论 -
leetcode 25 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原创 2014-05-06 22:58:09 · 389 阅读 · 0 评论 -
leetcode 26 Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.p原创 2014-05-06 22:59:21 · 386 阅读 · 0 评论 -
leetcode 151 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".click to show clarification.Clarification:What constitutes原创 2014-05-06 23:01:24 · 572 阅读 · 0 评论 -
LeetCode 23 Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2014-06-18 14:08:03 · 367 阅读 · 0 评论 -
LeetCode 34 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-06-18 14:11:42 · 410 阅读 · 0 评论 -
LeetCode 37 Count and Say
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原创 2014-06-18 14:15:26 · 1239 阅读 · 0 评论 -
LeetCode 40 First Missing Positive
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant原创 2014-06-18 14:21:41 · 385 阅读 · 0 评论 -
LeetCode 40 Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?原创 2014-06-18 14:26:57 · 392 阅读 · 0 评论 -
LeetCode 49 Pow(x, n)
Implement pow(x, n).原创 2014-06-18 14:28:37 · 476 阅读 · 0 评论 -
LeetCode 57 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原创 2014-06-18 14:37:16 · 331 阅读 · 0 评论 -
LeetCode 64 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.原创 2014-06-18 14:40:32 · 413 阅读 · 0 评论 -
LeetCode 65 Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return ”100”.原创 2014-06-18 14:52:41 · 396 阅读 · 0 评论 -
LeetCode 67 Plus One
Given a number represented as an array of digits, plus one to the number.原创 2014-06-18 14:56:18 · 434 阅读 · 0 评论