leetcode
tangcc_thu
这个作者很懒,什么都没留下…
展开
-
Leetcode-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原创 2017-08-19 09:50:56 · 195 阅读 · 0 评论 -
Leetcode-210: Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as原创 2017-08-22 21:13:33 · 156 阅读 · 0 评论 -
Leetcode-207: Course Schedule
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as原创 2017-08-22 15:01:58 · 174 阅读 · 0 评论 -
Leetcode-23: Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.将k个有序的列表归并成一个有序列表。思路:数据结构中学过的是k=2时的特例,不过实际都是每次都将所有列表中头元素最小的那个元素加入新的列表。有两种方法: 1)朴素的比较然后归并方法,对于每个新加入的元素都原创 2017-08-13 18:12:20 · 165 阅读 · 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-08-13 15:53:28 · 127 阅读 · 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 all va原创 2017-08-13 15:28:35 · 203 阅读 · 0 评论 -
Leetcode-100: Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.给了两颗原创 2017-08-19 11:10:29 · 153 阅读 · 0 评论 -
Leetcode-124: Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The pa原创 2017-08-20 15:03:58 · 160 阅读 · 0 评论 -
Leetcode-116: Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If t原创 2017-08-20 13:45:49 · 162 阅读 · 0 评论 -
Leetcode-117: Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extr原创 2017-08-20 14:12:25 · 161 阅读 · 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 end, the原创 2017-08-13 11:58:04 · 158 阅读 · 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 contain原创 2017-08-12 23:50:18 · 154 阅读 · 0 评论 -
Leetcode-3: Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the le原创 2017-08-12 17:08:32 · 149 阅读 · 0 评论 -
Leetcode-11: Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin原创 2017-08-12 20:46:57 · 155 阅读 · 0 评论 -
Leetcode-9: Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.思路:将数字的右半边逆序记录下来,与左半边比较。public class Solution { public boolean isPalindrome(int x) { if (x < 0 || (x !原创 2017-08-12 20:11:31 · 124 阅读 · 0 评论 -
Leetcode-5: Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.转载 2017-08-12 17:36:37 · 137 阅读 · 0 评论 -
Leetcode-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原创 2017-08-12 16:33:57 · 165 阅读 · 0 评论 -
Leetcode-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 sam原创 2017-08-12 16:28:47 · 142 阅读 · 0 评论 -
Leetcode-329: Longest Increasing Path in a Matrix
Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside o原创 2017-08-24 00:51:27 · 192 阅读 · 0 评论