LeetCode
六月二十七
乘风破浪会有时,直挂云帆济沧海。
展开
-
LeetCode- minimum-depth-of-binary-tree
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ /** * 题目名称:minimum-depth-of-b...原创 2019-03-14 09:46:33 · 133 阅读 · 0 评论 -
LeetCode-evaluate-reverse-polish-notation
Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"...原创 2019-03-14 09:51:01 · 209 阅读 · 0 评论 -
LeetCode-max-points-on-a-line
Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line./** * Definition for a point. * class Point { * int x; * int y; * Point() { x = 0...原创 2019-03-14 09:53:48 · 212 阅读 · 0 评论 -
LeetCode-sort-list
Sort a linked list inO(nlogn) time using constant space complexity./** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { *...原创 2019-03-14 09:56:57 · 417 阅读 · 0 评论 -
LeetCode- insertion-sort-list
Sort a linked list using insertion sort./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * ...原创 2019-03-14 09:59:03 · 175 阅读 · 0 评论 -
LeetCode-binary-tree-postorder-traversal
Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].Note:Recursive solution is trivial, c...原创 2019-03-14 10:01:43 · 169 阅读 · 0 评论 -
LeetCode-reorder-list
Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reorder it...原创 2019-03-14 10:04:24 · 179 阅读 · 0 评论 -
LeetCode-linked-list-cycle-ii
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * c...原创 2019-03-14 10:05:48 · 189 阅读 · 0 评论 -
LeetCode-linked-list-cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * class ListNode { * int val; * L...原创 2019-03-14 10:07:11 · 247 阅读 · 0 评论 -
LeetCode-copy-list-with-random-pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.import java.util.*;/** * Defini...原创 2019-03-15 09:24:37 · 266 阅读 · 0 评论 -
LeetCode-single-number-ii
Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using...原创 2019-03-15 09:26:51 · 300 阅读 · 0 评论 -
LeetCode-single-number
Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra...原创 2019-03-15 09:28:09 · 292 阅读 · 0 评论 -
LeetCode-candy
There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one ca...原创 2019-03-15 09:29:56 · 322 阅读 · 0 评论 -
LeetCode-gas-station
There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[i]of gas to travel from stationito its nex...原创 2019-03-15 09:31:44 · 246 阅读 · 0 评论 -
LeetCode-clone-graph
Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use#as a separator for each node, and,...原创 2019-03-15 09:33:20 · 187 阅读 · 0 评论 -
LeetCode- 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./** * Definition for binary tree * ...原创 2019-04-03 22:39:08 · 155 阅读 · 0 评论 -
LeetCode-binary-tree-zigzag-level-order-traversal
Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tre...原创 2019-04-03 22:40:29 · 120 阅读 · 0 评论 -
LeetCode-inary-tree-level-order-traversal
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,20,#,#,15,7}, 3 / \ 9 20 / \...原创 2019-04-03 22:41:52 · 113 阅读 · 0 评论 -
LeetCode-symmetric-tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the followi...原创 2019-04-03 22:43:53 · 150 阅读 · 0 评论 -
LeetCode-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./** * Defini...原创 2019-04-03 22:45:24 · 150 阅读 · 0 评论 -
LeetCode-recover-binary-search-tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devise a...原创 2019-04-03 22:46:34 · 192 阅读 · 0 评论 -
LeetCode-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 keysless thanthe node's key. The ...原创 2019-04-03 22:48:01 · 208 阅读 · 0 评论 -
LeetCode-interleaving-string
Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="aadbbbaccc", return false.p...原创 2019-04-03 22:49:24 · 233 阅读 · 0 评论 -
LeetCode-unique-binary-search-trees-ii
Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 unique BST's shown below. 1 3 ...原创 2019-04-03 22:50:27 · 124 阅读 · 0 评论 -
LeetCode- unique-binary-search-trees
Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ ...原创 2019-04-03 22:51:46 · 151 阅读 · 0 评论 -
LeetCode-palindrome-partitioning-ii
Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs.For example, givens="aab",Return1since...原创 2019-03-26 21:57:08 · 203 阅读 · 0 评论 -
LeetCode-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,X X X XX O O XX X O XX O X...原创 2019-03-26 22:00:05 · 168 阅读 · 0 评论 -
LeetCode-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 number123.Find the total sum...原创 2019-03-26 22:01:34 · 134 阅读 · 0 评论 -
LeetCode-palindrome-partitioning
Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, givens="aab",Return [ ["aa","b"],...原创 2019-03-26 21:58:37 · 391 阅读 · 0 评论 -
LeetCode-longest-consecutive-sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is[1, 2, 3, 4]. ...原创 2019-03-26 22:03:44 · 152 阅读 · 0 评论 -
LeetCode-binary-tree-inorder-traversal
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:Recursive solution is trivia...原创 2019-04-04 22:17:00 · 118 阅读 · 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"]. (Order does no...原创 2019-04-04 22:18:08 · 126 阅读 · 0 评论 -
LeetCode-reverse-linked-list-ii
Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.Note:G...原创 2019-04-04 22:19:03 · 191 阅读 · 0 评论 -
LeetCode-subsets-ii
Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order. The solution set must not contain duplicate...原创 2019-04-04 22:20:13 · 135 阅读 · 0 评论 -
LeetCode-decode-ways
A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the tota...原创 2019-04-04 22:21:20 · 169 阅读 · 0 评论 -
LeetCode-gray-code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gr...原创 2019-04-04 22:22:29 · 206 阅读 · 0 评论 -
LeetCode- merge-sorted-array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A ...原创 2019-04-04 22:23:37 · 128 阅读 · 0 评论 -
LeetCode-scramble-string
Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ofs1="great": great / \ gr ...原创 2019-04-04 22:24:45 · 159 阅读 · 0 评论 -
LeetCode-partition-list
Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each of t...原创 2019-04-04 22:26:07 · 131 阅读 · 0 评论 -
LeetCode-maximal-rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.public class Solution { public int maximalRectangle(char[][] matrix) { ...原创 2019-04-04 22:27:17 · 206 阅读 · 0 评论