随笔分类 - leetcode
记录leetcode算法语代码
摘要:作者:jostree 转载请注明出处http://www.cnblogs.com/jostree/p/4052721.html题目链接:leetcode Maximal Rectangle 单调栈该题目是 leetcode Largest Rectangle in Histogram的二维版本,首先...
阅读全文
摘要:作者:jostree 转载请注明出处http://www.cnblogs.com/jostree/p/4052343.html题目链接leetcode Largest Rectangle in Histogram 单调栈对于每一个长条都向前找包含这个长条的最大面积使可行的,但是时间复杂度是O(n^2...
阅读全文
摘要:作者:jostree 转载请注明出处http://www.cnblogs.com/jostree/p/4051776.html题目链接:leetcode Surrounded Regions对于每个边缘的'O'进行广度优先遍历,把他和与其相连接的'O'修改成'M'。这些被修改的点会保持自己的'O',...
阅读全文
摘要:作者:jostree转载请注明出处http://www.cnblogs.com/jostree/p/4051169.html题目链接:leetcode Permutations II 无重全排列题目要求对有重复的数组进行无重全排列。为了保证不重复,类似于全排列算法使用dfs,将第一个数字与后面第一次...
阅读全文
摘要:作者:jostree转载请注明出处http://www.cnblogs.com/jostree/p/4051169.html题目链接:leetcode Insert Interval使用模拟的方法,把需要插入的区间和每一个给定的区间进行比较,有三种情况:1.给定区间的起点小于要插入区间的终点,并且区...
阅读全文
摘要:作者:jostree转载请注明出处http://www.cnblogs.com/jostree/p/4051082.html题目链接:leetcode Edit Distance最短编辑距离,简单dp,dp[i,j]表示到str1的第i个字符和str2的第j个字符止的最短编辑距离。dp[i,j] =...
阅读全文
摘要:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not...
阅读全文
摘要:Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].给定...
阅读全文
摘要: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, 1 ...
阅读全文
摘要:Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For exa...
阅读全文
摘要:Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2...
阅读全文
摘要:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note...
阅读全文
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a...
阅读全文
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a...
阅读全文
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie...
阅读全文
摘要:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth...
阅读全文
摘要:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.输入一个字符串数组,返回所有回文构词法(anagrams)的字符串,所谓回...
阅读全文
摘要: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 ...
阅读全文
摘要:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".给定两个二进制的字符串,返回他们的和。对于a,b两个二进制字符串,首先通过交换使a的长度小于b...
阅读全文
摘要:Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of ...
阅读全文

浙公网安备 33010602011771号