自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(36)
  • 收藏
  • 关注

原创 2. Add Two Numbers

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...

2019-03-29 23:48:00 81

转载 72. Edit Distance

原博:https://blog.csdn.net/iyuanshuo/article/details/80112211典型的动态规划问题。首先定义状态矩阵,dp[m][n],其中m为word1的长度+1,n为word2的长度+1,为什么+1?因为要考虑如果word1或word2为空的情况,后面可以看到。定义dp[i][j]为word1中前ii个字符组成的串,与word2中前jj个字符组成的串...

2019-03-29 20:27:01 78

原创 485. Max Consecutive Ones

Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive 1s....

2019-03-27 17:56:20 70

原创 674. Longest Continuous Increasing Subsequence

Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray).Example 1:Input: [1,3,5,4,7]Output: 3Explanation: The longest continuous increasing sub...

2019-03-27 17:43:11 70

原创 300. Longest Increasing Subsequence

Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4Explanation: The longest increasing subsequence is [2,3,7,101], ...

2019-03-27 15:42:54 102

原创 152. Maximum Product Subarray(乘积最大子序列)

Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation: [2,3] has ...

2019-03-24 19:10:49 100

原创 120. Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[[2],[3,4],[6,5,7],[4,1,8,3]...

2019-03-24 17:45:21 93

原创 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?Note: Given n will be a positive i...

2019-03-24 17:22:21 67

原创 动态规划(Dynamic Programming)

1.递归+记忆化->递推2.状态的定义:opt[n],dp[n],fib[n]3.状态转移方程:opt[n]=best_of(opt[n-1],opt[n-2],…)4.最优子结构回溯(递归)----重复计算贪心 —永远局部最优DP --记录局部最优子结构/多种记录值...

2019-03-24 17:04:26 119

原创 212. Word Search II

Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizo...

2019-03-24 16:22:42 147

原创 338. Counting Bits

Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example 1:Input: 2Output...

2019-03-24 14:29:35 129

原创 231. Power of Two

Given an integer, write a function to determine if it is a power of two.Example 1:Input: 1Output: trueExplanation: 2^0 = 1Example 2:Input: 16Output: trueExplanation: 2^4 = 16Example 3:Input:...

2019-03-24 14:13:32 80

原创 191. Number of 1 Bits

Write a function that takes an unsigned integer and return the number of ‘1’ bits it has (also known as the Hamming weight).Example 1:Input: 00000000000000000000000000001011Output: 3Explanation: T...

2019-03-24 13:57:53 92

原创 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 vertically ne...

2019-03-23 17:05:12 103

原创 trie

trie,又称前缀树或字典树。它利用字符串的公共前缀来节约存储空间。性质(1)根节点不包含字符,除根节点外的每个节点只包含一个字符。(2)从根节点到某一个节点,路径上经过的字符连接起来,为该节点对应的字符串。(3)每个节点的所有子节点包含的字符串不相同。class Trie(object): def __init__(self): """ Ini...

2019-03-23 16:35:06 112

原创 69. Sqrt(x)

Implement int sqrt(int x).Compute and return the square root of x, where x is guaranteed to be a non-negative integer.Since the return type is an integer, the decimal digits are truncated and only t...

2019-03-20 21:33:37 85

原创 排序算法

十种常见排序算法可以分为两大类:比较类排序:通过比较来决定元素间的相对次序,由于其时间复杂度不能突破O(nlogn),因此也称为非线性时间比较类排序。(1)交换排序:冒泡排序 和 快速排序(2)插入排序:简单插入排序 和 希尔排序(3)选择排序:简单选择排序 和 堆排序(4)归并排序:二路归并排序 和 多路归并排序非比较类排序:不通过比较来决定元素间的相对次序,它可以突破基于...

2019-03-19 21:59:52 327 2

原创 51. N-Queens

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each s...

2019-03-19 21:20:20 90

原创 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:[“((()))”,“(()())”,“(())()”,“()(())”,“()()()”...

2019-03-19 00:21:37 78

原创 111. Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Note: A leaf is a node with no children....

2019-03-19 00:05:36 71

原创 104. Maximum Depth of Binary Tree

Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A leaf is a node with no children....

2019-03-18 23:50:52 91

原创 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 element alway...

2019-03-18 22:15:11 75

原创 50. Pow(x, n)

Implement pow(x, n), which calculates x raised to the power n (xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:python:分治思想class Solution...

2019-03-18 22:01:26 94

原创 20. Valid Parentheses

Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of bra...

2019-03-16 19:41:00 52

原创 921. Minimum Add to Make Parentheses Valid

Given a string S of ‘(’ and ‘)’ parentheses, we add the minimum number of parentheses ( ‘(’ or ‘)’, and in any positions ) so that the resulting parentheses string is valid.Formally, a parentheses st...

2019-03-16 19:26:48 73

原创 242. Valid Anagram

Given two strings s and t , write a function to determine if t is an anagram of s.Example 1:Input: s = “anagram”, t = “nagaram”Output: trueExample 2:Input: s = “rat”, t = “car”Output: falseclas...

2019-03-16 18:40:35 50

原创 98. Validate Binary Search Tree

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.The rig...

2019-03-15 23:45:49 44

原创 236. Lowest Common Ancestor of a Binary Tree

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p a...

2019-03-15 18:35:43 69

原创 206. Reverse Linked List

Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLpython:class Solution(object): def reverseList(

2019-03-14 21:30:50 77

原创 876. Middle of the Linked List

Given a non-empty, singly linked list with head node head, return a middle node of linked list.If there are two middle nodes, return the second middle node.Example 1:Input: [1,2,3,4,5]Output: Node...

2019-03-13 23:49:28 60

原创 929. Unique Email Addresses

Every email consists of a local name and a domain name, separated by the @ sign.For example, in [email protected], alice is the local name, and leetcode.com is the domain name.Besides lowercase let...

2019-03-13 23:44:43 127

原创 771. Jewels and Stones

You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the sto...

2019-03-13 00:14:12 66

原创 762. Prime Number of Set Bits in Binary Representation

Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation.(Recall that the number of set bits an integer h...

2019-03-13 00:10:33 51

原创 1. Two Sum

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 same e...

2019-03-13 00:03:55 45

原创 102. Binary Tree Level Order Traversal

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 20/ 15 7retu...

2019-03-12 23:53:49 57

原创 从零开始学python(一):序列

序列:1.列表2.元组3.字符串4.字典通用序列操作:1.索引(访问单个元素):从0开始递增,若使用负数,最右边元素(即最后一个)为-1。(原因:不能和第一个元素重复)2.分片(访问一定范围内元素):通过冒号隔开的两个索引实现。[ )例:>>>numbers=[1,2,3,4,5,6,7,8,9,10]&gt

2019-03-01 08:07:16 248

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除