leetcode
helloJeremy1996
这个作者很懒,什么都没留下…
展开
-
leetcode 91. Decode Ways
题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, determine the t原创 2017-02-28 17:28:44 · 320 阅读 · 0 评论 -
leetcode 69. Sqrt(x)
题目:求x的平方根 思路:牛顿法,https://en.wikipedia.org/wiki/Newton%27s_method class Solution(object): def mySqrt(self, x): """ :type x: int :rtype: int """ if x=原创 2017-02-24 22:20:35 · 237 阅读 · 0 评论 -
leetcode 88. Merge Sorted Array
题目:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. 思路:二分查找+插入 class Solution(object): def merge(self, nums1, m, nums2, n): """原创 2017-02-25 15:06:19 · 230 阅读 · 0 评论 -
98. Validate Binary Search Tree
题目:判断是不是搜索二叉树 思路:1.中序遍历的序列是严格递增的。2.节点的左子树上的值均小于该节点的值,右子树的值均大于该节点的值。 1.class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = No原创 2017-02-27 10:50:30 · 217 阅读 · 0 评论 -
94. Binary Tree Inorder Traversal
题目:中序遍历二叉树 思路:递归 # Definition for a binary tree node. class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class S原创 2017-02-27 11:23:40 · 206 阅读 · 0 评论 -
LeetCode 79. Word Search
题目: Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or ver原创 2017-03-23 18:51:08 · 340 阅读 · 0 评论 -
Leetcode 8. String to Integer (atoi)
题目:Implement atoi to convert a string to an integer. 思路:编写相应规则即可. import ctypes class Solution(object): def myAtoi(self, str): """ :type str: str :rtype: int原创 2017-03-24 10:36:59 · 262 阅读 · 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: The solution set must not contai原创 2017-03-25 16:03:23 · 258 阅读 · 0 评论 -
Leetcode 62. 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 rea原创 2017-03-26 11:09:45 · 277 阅读 · 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 e原创 2017-04-24 10:59:44 · 268 阅读 · 0 评论 -
leetcode 70. Climbing Stairs
题目: 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? 思路:动态规划,n可以看做前n-1步的解法原创 2017-02-24 21:58:57 · 218 阅读 · 0 评论 -
leetcode 66. Plus One
题目: Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leading zero, except the number 0 itself. T原创 2017-02-23 11:25:27 · 264 阅读 · 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原创 2017-02-20 10:00:24 · 215 阅读 · 0 评论 -
leetcode 84. Largest Rectangle in Histogram
题目: Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where原创 2017-03-01 10:28:18 · 266 阅读 · 0 评论 -
leetcode 21. 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. 思路:链表合并。1判空,2.找到头节点head,r=head,3.当l1,l2都不为空时逐个判断并下移指针,原创 2017-02-21 10:58:37 · 211 阅读 · 0 评论 -
leetcode 26. Remove Duplicates from Sorted Array
题目: Total Accepted: 199594Total Submissions: 563740Difficulty: EasyContributors: Admi Given a sorted array, remove the duplicates in place such that each element appear only once and return原创 2017-02-21 12:19:04 · 232 阅读 · 0 评论 -
leetcode 28. Implement strStr()
题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 思路:模式匹配问题,即在原始串中寻找第一个匹配目标串的位置。利用KMP算法,分两步,1.求next数组 2.根据next原创 2017-02-22 10:41:25 · 236 阅读 · 0 评论 -
leetcode 38. 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原创 2017-02-22 11:05:33 · 206 阅读 · 0 评论 -
leetcode 53. Maximum Subarray
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum. 最大子列和 思路:在线搜索O(n) class Solution(object): def maxSubArray(self, nums):原创 2017-02-23 10:59:43 · 181 阅读 · 0 评论 -
leetcode 53. Maximum Subarray
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum. 最大子列和 思路:在线搜索 class Solution(object): def maxSubArray(self, nums): "原创 2017-02-23 11:02:33 · 216 阅读 · 0 评论 -
leetcode 66. Plus One
题目: Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leading zero, except the number 0 itself. T原创 2017-02-23 11:23:27 · 250 阅读 · 0 评论 -
Leetcode 22. Generate Parentheses
题目: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()",原创 2017-04-24 15:22:38 · 313 阅读 · 0 评论