
leetcode题解
文章平均质量分 59
归类总结分析leetcode的151道题,结合图解和AC代码,从树的遍历、链表操作、动态规划等各种数据结构知识点进行分析。
樱桃小猴子atZJU
这个作者很懒,什么都没留下…
展开
-
【leetcode】ZigZag Conversion
题目:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I GY I RAnd then read line by line: "PAHNAPLSIIG原创 2014-08-11 21:53:39 · 769 阅读 · 0 评论 -
【leetcode】Add Two Numbers 解析以及拓展
题目: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 digit. Add the two numbers and return it as a linked list.Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)Outpu原创 2014-08-10 10:19:04 · 1074 阅读 · 0 评论 -
【leetcode】Longest Substring Without Repeating Characters
题目:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the lengt原创 2014-08-08 23:39:06 · 619 阅读 · 0 评论 -
【leetcode X Sum 系列】Two Sum|3Sum|3Sum Closest|4Sum
Two Sum 题目:My SubmissionsGiven an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than ind原创 2014-08-07 20:40:47 · 928 阅读 · 0 评论 -
【leetcode】Surrounded Regions
类似于中国围棋的二维字符数组,将被'X'包围的'O'全部转化为'X',不同的是,与边缘接轨的'O'不用转化为'X',所以切入点在于边缘的‘O’,从边缘开始做DFS或者BFS,由于用例有200*200的棋盘,使用Java写DFS会因为递归太多层报Stackoverflow的错误,用C++实现能够AC:原创 2014-08-04 20:08:03 · 590 阅读 · 0 评论 -
【leetcode】Balanced Binary Tree
题目: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 of the two subtrees of every node ne原创 2014-07-29 22:46:36 · 668 阅读 · 0 评论 -
【leetcode】Interleaving String
题目:Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbba原创 2014-07-23 20:15:03 · 453 阅读 · 0 评论 -
【leetcode】Restore IP Addresses
题目:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]原创 2014-07-21 22:41:00 · 460 阅读 · 0 评论 -
【leetcode】Decode Ways
题目:A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the原创 2014-07-21 21:25:44 · 454 阅读 · 0 评论 -
【leetcode】Container With Most Water
题目:给一组数组作为水池的高度,以其中两个高度作为水池的壁,求最大的水池容量。假设左边的壁为left,右边的壁为right,则水池容量capacity= (right-left)*min(height(right),height(right))定义两个指针left和right从数组两头开始遍历:如果left的高度低于right,则将left指针右移找原创 2014-07-17 15:33:31 · 562 阅读 · 0 评论 -
【leetcode】Roman to Integer | Integer to Roman
题目:【leetcode】12 Integer to Roman(将阿拉伯数字转换成罗马数字)原创 2014-07-17 15:32:32 · 536 阅读 · 0 评论 -
【leetcode】 Longest Common Prefix
求字符串数组中所有数组的最长公共前缀,代码很简单,但是要很注重细节边界值输入要特别注意,比如:[] 输入空的字符串数组,要判断 if (strs .size() == 0) return "";[""] 字符串数组里面只有一个空字符串等情况等等。原创 2014-07-17 15:24:37 · 499 阅读 · 0 评论 -
【leetcode】Valid Parentheses
题目:这道题原创 2014-07-17 15:21:55 · 396 阅读 · 0 评论 -
【leetcode】Edit Distance
题目:编辑距离问题是原创 2014-07-17 15:15:17 · 481 阅读 · 0 评论 -
【leetcode】Spiral Matrix
今天在命令行用ant跑junit时候一直出现错误java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing查了很多资料,原来要将junit的jar包拷贝到ANT_HOME/lib下。但是之后错误还是存在,看到解释是版本问题,有提出要添加hamcrest.jar包的,试过没用。原创 2014-07-17 14:45:58 · 514 阅读 · 0 评论