LeetCode题解
文章平均质量分 66
LeetCode 解题心得,思路,代码分享。
xujian_2014
这个作者很懒,什么都没留下…
展开
-
【LeetCode OJ 101】Symmetric Tree
题目链接:https://leetcode.com/problems/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:原创 2016-04-01 15:17:38 · 753 阅读 · 0 评论 -
【LeetCode OJ 075】Sort Colors
题目链接:https://leetcode.com/problems/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 r原创 2016-03-27 12:59:55 · 861 阅读 · 0 评论 -
【LeetCode OJ 073】Set Matrix Zeroes
题目链接:https://leetcode.com/problems/set-matrix-zeroes/题目:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A str原创 2016-03-13 20:08:20 · 1069 阅读 · 0 评论 -
【LeetCode OJ 090】Subsets II
题目链接:https://leetcode.com/problems/subsets-ii/题目:Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note:Elements in a subset must be in non-原创 2016-03-12 14:48:58 · 1030 阅读 · 0 评论 -
【LeetCode OJ 078】Subsets
题目链接:https://leetcode.com/problems/subsets/题目:Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution s原创 2016-03-12 14:42:41 · 1099 阅读 · 0 评论 -
【LeetCode OJ 268】Missing Number
题目链接:https://leetcode.com/problems/missing-number/题目: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原创 2016-03-02 21:30:07 · 975 阅读 · 0 评论 -
【LeetCode OJ 328】Odd Even Linked List
题目链接:https://leetcode.com/problems/odd-even-linked-list/题目:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node numbe原创 2016-03-02 17:09:53 · 1039 阅读 · 0 评论 -
【LeetCode OJ 061】Rotate List
题目链接:https://leetcode.com/problems/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原创 2016-03-01 15:08:10 · 735 阅读 · 0 评论 -
【LeetCode OJ 203】Remove Linked List Elements
题目链接:https://leetcode.com/problems/remove-linked-list-elements/题目:Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, va原创 2016-02-28 19:53:34 · 1022 阅读 · 0 评论 -
【LeetCode OJ 225】Implement Stack using Queues
题目链接:https://leetcode.com/problems/implement-stack-using-queues/题目:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on原创 2016-02-26 10:17:41 · 1217 阅读 · 0 评论 -
【LeetCode OJ 232】Implement Queue using Stacks
题目链接:https://leetcode.com/problems/implement-queue-using-stacks/题目:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the原创 2016-02-25 21:02:13 · 1204 阅读 · 0 评论 -
【LeetCode OJ 20】Valid Parentheses
题目链接:https://leetcode.com/problems/valid-parentheses/题目:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must原创 2016-02-23 20:54:39 · 840 阅读 · 0 评论 -
【LeetCode OJ 14】Longest Common Prefix
题目链接:https://leetcode.com/problems/longest-common-prefix/题目:Write a function to find the longest common prefix string amongst an array of strings.解题思路:寻找字符串数组的最长公共前缀,将数组的第一个元素作为默认公共前缀,依次与后面的元素进行比较原创 2016-02-23 20:21:55 · 1233 阅读 · 1 评论 -
【LeetCode OJ 28】Implement strStr()
题目链接:https://leetcode.com/problems/implement-strstr/题目:implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.解题思路:题意为在字符原创 2016-01-26 16:53:20 · 1062 阅读 · 1 评论 -
【LeetCode OJ 260】Single Number III
题目链接:https://leetcode.com/problems/single-number-iii/题目:Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two原创 2016-01-25 16:30:53 · 1742 阅读 · 3 评论 -
【LeetCode OJ 41】First Missing Positive
题目链接:https://leetcode.com/problems/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原创 2016-01-25 09:18:28 · 702 阅读 · 0 评论 -
【LeetCode OJ 136】Single Number
题目链接:https://leetcode.com/problems/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 runt原创 2016-01-21 16:11:36 · 2510 阅读 · 0 评论 -
【LeetCode OJ 34】Search for a Range
题目链接:https://leetcode.com/problems/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原创 2016-01-21 11:06:51 · 1171 阅读 · 0 评论 -
【LeetCode OJ 237】Delete Node in a Linked List
题目链接:https://leetcode.com/problems/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原创 2016-01-20 15:03:51 · 1338 阅读 · 0 评论 -
【LeetCode OJ 263】Ugly Number
题目链接:https://leetcode.com/problems/ugly-number/题目: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. Fo原创 2016-01-19 22:01:13 · 1423 阅读 · 0 评论 -
【LeetCode OJ 016】3Sum Closest
题目链接:https://leetcode.com/problems/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 in原创 2016-01-19 21:20:17 · 993 阅读 · 0 评论 -
【LeetCode OJ 242】Valid Anagram
题目链接:https://leetcode.com/problems/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原创 2016-01-18 19:53:18 · 1307 阅读 · 0 评论 -
【LeetCode OJ 258】Add Digits
题目链接:https://leetcode.com/problems/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 pro原创 2016-01-15 20:18:50 · 822 阅读 · 0 评论 -
【LeetCode OJ 169】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 ele原创 2015-03-28 14:24:01 · 535 阅读 · 0 评论 -
【LeetCode OJ 019】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,原创 2015-03-31 14:53:58 · 615 阅读 · 0 评论 -
【LeetCode OJ 021】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.struct ListNode { int val; ListNode *next; ListNo原创 2015-04-01 09:15:25 · 636 阅读 · 0 评论 -
【LeetCode OJ 024】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原创 2015-04-02 09:09:37 · 571 阅读 · 0 评论 -
【LeetCode OJ 026】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 w原创 2015-04-03 14:46:27 · 629 阅读 · 0 评论 -
【LeetCode OJ 100】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.解题思路:这题原创 2015-05-02 16:05:57 · 695 阅读 · 0 评论 -
【LeetCode OJ 027】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.原创 2015-04-07 09:10:44 · 599 阅读 · 0 评论 -
【LeetCode OJ 035】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 arr原创 2015-04-08 14:39:47 · 614 阅读 · 0 评论 -
【LeetCode OJ 015】3Sum
题目链接:https://leetcode.com/problems/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原创 2015-11-23 11:05:25 · 565 阅读 · 0 评论 -
【LeetCode OJ 011】Container With Most Water
链接:https://leetcode.com/problems/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 s原创 2015-11-22 13:17:42 · 643 阅读 · 0 评论 -
【LeetCode OJ 009】Palindrome Number
题目链接:https://leetcode.com/problems/palindrome-number/题目:Determine whether an integer is a palindrome. Do this without extra space.Could negative integers be palindromes? (ie, -1)If you are原创 2015-11-20 20:27:59 · 480 阅读 · 0 评论 -
【LeetCode OJ 228】Summary Ranges
题目链接:https://leetcode.com/problems/summary-ranges/题目:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5"原创 2015-11-20 09:49:28 · 496 阅读 · 0 评论 -
【LeetCode OJ 007】Reverse Integer
题目链接:https://leetcode.com/problems/reverse-integer/题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Have you thought about this?Here are原创 2015-11-16 20:31:38 · 1271 阅读 · 0 评论 -
【LeetCode OJ 005】Longest Palindromic Substring
题目链接:https://leetcode.com/problems/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原创 2015-11-07 20:54:34 · 503 阅读 · 0 评论 -
【LeetCode OJ 004】Median of Two Sorted Arrays
题目链接:https://leetcode.com/problems/median-of-two-sorted-arrays/题目:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall ru原创 2015-11-06 09:07:13 · 1134 阅读 · 0 评论 -
【LeetCode OJ 003】Longest Substring Without Repeating Characters
题目链接:https://leetcode.com/problems/longest-substring-without-repeating-characters/题目:Given a string, find the length of the longest substring without repeating characters. For example, the longest原创 2015-11-05 20:27:42 · 1034 阅读 · 0 评论 -
【LeetCode OJ 002】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 l原创 2015-03-23 20:16:27 · 444 阅读 · 0 评论