
LeetCode-P
茶生
混吃等死
展开
-
LeetCode 1.Two Sum (Python)
题目描述: 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, and you may not use the s原创 2017-07-12 15:13:45 · 300 阅读 · 0 评论 -
LeetCode 101. Symmetric Tree(Python)
题目描述: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3原创 2017-08-19 21:46:24 · 325 阅读 · 0 评论 -
LeetCode 49. Group Anagrams (Python)
题目描述: Given an array of strings, group anagrams together.For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]Note: All inputs原创 2017-08-05 19:28:54 · 1947 阅读 · 0 评论 -
LeetCode 102. Binary Tree Level Order Traversal(Python)
题目描述: Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9原创 2017-08-20 16:40:43 · 348 阅读 · 0 评论 -
LeetCode 78. Subsets (Python)
题目描述: Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example, If nums = [1,2,3], a solution is: [ [3], [1],原创 2017-08-13 21:16:47 · 572 阅读 · 0 评论 -
LeetCode 11. Container With Most Water (Python)
题目描述: 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). Find原创 2017-07-28 20:27:53 · 494 阅读 · 0 评论 -
LeetCode 114. Flatten Binary Tree to Linked List(Python)
题目描述: Given a binary tree, flatten it to a linked list in-place.For example, Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like:1 \ 2 \ 3 \ 4原创 2017-08-21 22:10:01 · 1132 阅读 · 0 评论 -
LeetCode 169. Majority Element(Python)
题目描述: 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原创 2017-08-25 19:58:41 · 475 阅读 · 0 评论 -
LeetCode 198. House Robber(Python)
题目描述: 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原创 2017-08-25 20:22:50 · 643 阅读 · 0 评论 -
LeetCode 98. Validate Binary Search Tree (Python)
题目描述: Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node’s key. Th原创 2017-08-15 21:36:20 · 327 阅读 · 0 评论 -
LeetCode 64. Minimum Path Sum(Python)
题目描述: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right原创 2017-08-19 15:19:13 · 504 阅读 · 0 评论 -
LeetCode 59. Spiral Matrix II(Python)
题目描述: Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example, Given n = 3,You should return the following matrix: [ [ 1, 2, 3 ], [ 8, 9原创 2017-08-18 21:32:02 · 957 阅读 · 0 评论 -
LeetCode 70. Climbing Stairs (Python)
题目描述: You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positi原创 2017-08-09 19:17:24 · 704 阅读 · 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 exa原创 2017-07-12 15:17:58 · 273 阅读 · 0 评论 -
LeetCode 7.Reverse Integer
题目描述:Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321Note: The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reverse原创 2017-07-12 15:47:27 · 394 阅读 · 0 评论 -
LeetCode 234. Palindrome Linked List
题目描述: Given a singly linked list, determine if it is a palindrome.Follow up: Could you do it in O(n) time and O(1) space?AC代码:class Solution(object): def isPalindrome(self, head): """原创 2017-07-16 17:21:25 · 220 阅读 · 0 评论 -
LeetCode 19. Remove Nth Node From End of List (Python)
题目描述: 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 linked原创 2017-07-30 22:28:59 · 334 阅读 · 0 评论 -
LeetCode 24. Swap Nodes in Pairs (Python)
题目描述: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. You ma原创 2017-07-31 21:40:14 · 346 阅读 · 0 评论 -
LeetCode 56. Merge Intervals (Python)
题目描述: Given a collection of intervals, merge all overlapping intervals.For example: Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18].AC代码:class Solution(object): def merge(self, int原创 2017-08-07 19:26:00 · 842 阅读 · 0 评论 -
LeetCode 62. Unique Paths (Python)
题目描述: 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 th原创 2017-08-08 20:19:50 · 1641 阅读 · 0 评论 -
LeetCode 63. Unique Paths II (Python)
题目描述: Follow up for “Unique Paths”:Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid原创 2017-08-08 21:36:40 · 1214 阅读 · 0 评论 -
LeetCode 34. Search for a Range (Python)
题目描述: Given an array of integers sorted in ascending order, 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 ta原创 2017-08-02 16:53:02 · 1165 阅读 · 0 评论 -
LeetCode 226. Invert Binary Tree(Python)
题目描述: Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1思路: 运用递归前序遍历二叉树来实现交换AC代码:class Solution(object): def invertTree(self,原创 2017-08-27 14:42:43 · 477 阅读 · 0 评论