
leetcode
zycxnanwang
这个作者很懒,什么都没留下…
展开
-
sum-root-to-leaf-numbers
sum-root-to-leaf-numbers题目描述 Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number. An example is the root-to-leaf path1->2->3which represents the nu原创 2017-08-16 11:47:17 · 403 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node I, II
Populating Next Right Pointers in Each Node I, II题目I Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Popula原创 2017-09-10 17:53:07 · 359 阅读 · 0 评论 -
最长回文子串
最长回文子串 基本的思想:动态规划,是一种解决方法class Solution(object): def longestPalindrome(self, s): """ :type s: str :rtype: str """ length = len(s) arr = [[...原创 2018-06-30 18:45:41 · 206 阅读 · 0 评论 -
LeetCode分隔链表
LeetCode分隔链表题目链接地址解题思路 用双链表法 链表一: 1->2->2 链表二:4->3->5python代码# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# ...原创 2018-08-28 13:38:11 · 308 阅读 · 0 评论 -
LeetCode反转链表II
LeetCode反转链表II题目链接地址解题思路 1->2->3->4->5->NULL 分解成 1->NULL 2->3->4->NULL 5->NULL 然后对中间进行反转 算法的复杂度很小,性能很号 别看代码很长,其实很简单!python代码# Def...原创 2018-08-28 13:40:50 · 902 阅读 · 0 评论 -
LeetCode 通配符匹配
LeetCode 通配符匹配原题链接地址解题说明 一开始没有意思到这是到动态规划的题目,走了很多弯路,其实很容易想出来 只有三种转移条件 ’?’ 匹配 单个字符, 单个字符匹配单个字符 ‘*’ 号匹配零个字符 ‘*’号匹配两个以上个字符Python代码class Solution(object): def isMatch(self, s, ...原创 2018-08-28 13:42:46 · 479 阅读 · 0 评论 -
LeetCode编辑距离
LeetCode编辑距离原题链接地址解题说明 本题是一道非常典型的动态规划题 只有三种操作,代码里面都有描述,非常清晰 插入一个字符 删除一个字符 替换一个字符python代码class Solution(object): def minDistance(self, word1, word2): """ :type ...原创 2018-08-28 13:44:14 · 663 阅读 · 0 评论 -
Leetcode 218 天际线问题
Leetcode 218 天际线问题天际线问题思路可以看成一个归并问题切分的时候,如果剩一个元素,返回它表示的两个轮廓点,如果为空,返回空合并是重点:维护两个变量:h1,h2 h1表示左半部分当前位置高度,h2表示右半部分当前位置高度如果当前位置左半部分横坐标更小,就更新h1,从左半部分选元素;如果当前位置右半部分横坐标更小,就更新h2,从右半部分选元素;...原创 2018-10-09 21:55:55 · 1188 阅读 · 0 评论 -
最长回文子序列
最长回文子序列题目给定一个字符串s,找到其中最长的回文子序列例如输入:bbbab,最大回文子序列长度为4,结果为bbbb分析 题目其实和最大公共子序列很相似。比较字符串的第一个字符s1s_1s1和最后一个字符sns_nsn,如果它们相等。则原问题F(1,n)F(1,n)F(1,n)最优解为F(2,n−1)+2F(2,n-1)+2F(2,n−1)+2,F(2,n−1)F(2,n-1...原创 2018-12-26 19:10:49 · 312 阅读 · 0 评论 -
最长回文子串
最长回文子串题目给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。示例 1:输入: "babad"输出: "bab"注意: "aba" 也是一个有效答案。分析 可以用动态规划来做,复杂度为O(n2)O(n^2)O(n2),复杂度太高,以后改进!通过分析我们可以知道,长度为1的子字符串,是回文,长度为2的子字符串,如果两个字符相等是回文串...原创 2018-12-26 19:11:57 · 195 阅读 · 0 评论 -
surrounded-regions
surrounded-regions题目描述 Given a 2D board containing’X’and’O’, capture all regions surrounded by’X’. A region is captured by flipping all’O’s into’X’s in that surrounded region For example,原创 2017-08-15 18:13:25 · 300 阅读 · 0 评论 -
palindrome-partition-ii
palindrome-partition-ii题目描述 Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For原创 2017-08-15 16:44:08 · 510 阅读 · 0 评论 -
longest-consecutive-sequence
longest-consecutive-sequence题目描述 Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, For example,Given[100, 4, 200, 1, 3, 2],原创 2017-08-16 11:59:29 · 394 阅读 · 0 评论 -
word-ladder
word-ladder题目描述 Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: Only one letter can be changed at a time原创 2017-08-17 10:21:22 · 460 阅读 · 0 评论 -
binary-tree-maximum-path-sum
binary-tree-maximum-path-sum题目描述 Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree,原创 2017-08-17 18:14:31 · 290 阅读 · 0 评论 -
binary-tree-postorder-traversal
binary-tree-postorder-traversal Given a binary tree, return the *postorder*traversal of its nodes’ values. For example: For example: Given binary tree{1,#,2,3}, 1\2/3 return原创 2017-08-13 11:39:49 · 474 阅读 · 0 评论 -
reorder-list
reorder-list Given a singly linked list L: L 0→L 1→…→L n-1→L n, reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→… You must do this in-place without altering the nodes’ values. For example,原创 2017-08-13 17:51:37 · 409 阅读 · 0 评论 -
single-number
single-number题目描述 Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you原创 2017-08-14 16:00:06 · 322 阅读 · 0 评论 -
word-break
word-break题目描述 Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s =”leetcod原创 2017-08-15 10:26:31 · 343 阅读 · 0 评论 -
word-break-ii
word-break-ii题目描述 Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. Fo原创 2017-08-15 10:27:19 · 395 阅读 · 0 评论 -
palindrome-partitioning
palindrome-partitioning题目描述 Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s原创 2017-08-15 16:37:40 · 332 阅读 · 0 评论 -
找两个排序数组的中位数
找两个排序数组的中位数令两个排序数组大小分别是m,n如果m+n是奇数,中位数就是第m+n2+1\frac{m+n}{2}+12m+n+1个元素如果m+n是偶数,中位数就是第m+n2\frac{m+n}{2}2m+n个元素和第m+n2+1\frac{m+n}{2}+12m+n+1个元素的平均值自然而然得,问题转换为求两个排序数组中第kkk大的元素求排序数组中第k大的元素的算法...原创 2018-12-19 12:18:31 · 871 阅读 · 0 评论