![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LEETCODE
文章平均质量分 71
Alice熹爱学习
做个终身学习者,持续迭代;公众号-极客X养成计划;简书-不会停的蜗牛
展开
-
【LEETCODE】107-Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2015-11-02 19:23:09 · 529 阅读 · 0 评论 -
【LEETCODE】226-Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1# Definition for a binary tree node.# class TreeNode原创 2015-10-31 18:43:32 · 778 阅读 · 0 评论 -
【LEETCODE】173-Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next() and原创 2015-11-05 14:48:17 · 904 阅读 · 0 评论 -
【LEETCODE】110-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 ofevery node never differ原创 2015-11-01 11:55:27 · 622 阅读 · 0 评论 -
【LEETCODE】105-Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.# Definition for a binary tree node.# class TreeNode(o原创 2015-11-11 14:07:49 · 586 阅读 · 0 评论 -
【LEETCODE】109-Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.# Definition for singly-linked list.# class ListNode(object):# def __init__(sel原创 2015-11-09 17:16:00 · 630 阅读 · 0 评论 -
【LEETCODE】114-Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1原创 2015-11-06 19:16:09 · 635 阅读 · 0 评论 -
【LEETCODE】96-Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2015-11-03 22:07:33 · 499 阅读 · 0 评论 -
【LEETCODE】257-Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]# Defi原创 2015-11-01 20:16:30 · 632 阅读 · 0 评论 -
【LEETCODE】235-Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betwee原创 2015-10-31 20:40:04 · 522 阅读 · 0 评论 -
【LEETCODE】100-Same Tree
Same TreeGiven 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原创 2015-10-31 17:53:47 · 711 阅读 · 0 评论 -
【LEETCODE】104-Maximum Depth of Binary Tree
Maximum Depth of Binary TreeGiven 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.原创 2015-10-31 10:56:04 · 1147 阅读 · 0 评论 -
【LEETCODE】236-Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes原创 2015-11-10 17:09:33 · 443 阅读 · 0 评论 -
【LEETCODE】95-Unique Binary Search Trees II
Given n, generate all structurally uniqueBST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3原创 2015-11-04 10:28:34 · 431 阅读 · 0 评论 -
【LEETCODE】94-Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.原创 2015-11-03 19:00:31 · 473 阅读 · 0 评论 -
【LEETCODE】145-Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solution i原创 2015-11-03 11:30:33 · 437 阅读 · 0 评论 -
【LEETCODE】106-Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.参考:https://github.com/kamyu104/LeetCode/blob/master/原创 2015-11-10 11:01:39 · 559 阅读 · 0 评论 -
【LEETCODE】199-Binary Tree Right Side View
Given a binary tree, imagine yourself standing on theright side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1原创 2015-11-05 21:27:14 · 752 阅读 · 0 评论 -
【LEETCODE】108-Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):#原创 2015-11-04 20:17:48 · 544 阅读 · 0 评论 -
【LEETCODE】144-Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].参考:http://bookshadow.原创 2015-11-03 16:32:40 · 542 阅读 · 0 评论 -
【LEETCODE】102-Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal 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 /原创 2015-11-02 16:51:57 · 506 阅读 · 0 评论 -
【LEETCODE】101-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 fo原创 2015-11-01 16:29:42 · 589 阅读 · 0 评论 -
【LEETCODE】111-Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.# Definition for a binary tree nod原创 2015-10-31 19:56:41 · 596 阅读 · 0 评论 -
【LEETCODE】ADD DIGITS
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like:3 + 8 = 11, 1 + 1 = 2.Since 2 has only one d原创 2015-10-30 18:54:30 · 1138 阅读 · 0 评论 -
【LEETCODE】53-Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] has原创 2015-12-10 16:04:51 · 442 阅读 · 0 评论 -
【LEETCODE】240-Search a 2D Matrix II
Write an efficient algorithm that searches for a value in anm x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in原创 2015-12-09 19:00:06 · 488 阅读 · 0 评论 -
【LEETCODE】237-Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2015-11-24 15:45:33 · 426 阅读 · 0 评论 -
【LEETCODE】292-Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the原创 2015-11-24 15:07:25 · 505 阅读 · 0 评论 -
【LEETCODE】215-Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.N原创 2015-12-10 19:31:21 · 556 阅读 · 0 评论 -
【LEETCODE】206-Reverse Linked List
Reverse a singly linked list.迭代:# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Sol原创 2015-11-24 16:54:48 · 459 阅读 · 0 评论 -
【LEETCODE】141-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?参考:http://www.cnblogs.com/zuoyuan/p/3701639.html用快慢指针,因为fast指针移动的速度是slow原创 2015-11-24 20:11:25 · 834 阅读 · 0 评论 -
【LEETCODE】203-Remove Linked List Elements
Remove all elements from a linked list of integers that have valueval.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val = 6Return: 1 --> 2 --> 3 --> 4 --> 5# Definition for singl原创 2015-11-24 17:51:01 · 408 阅读 · 0 评论 -
【LEETCODE】241-Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are+, - and*.Example 1原创 2015-12-11 16:58:54 · 962 阅读 · 0 评论 -
【LEETCODE】234-Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?参考:http://bookshadow.com/weblog/2015/07/10/leetcode-palindrome-linked-list原创 2015-11-24 20:02:31 · 439 阅读 · 0 评论 -
【LEETCODE】299-Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t原创 2015-12-26 21:23:54 · 640 阅读 · 0 评论 -
【LEETCODE】223-Rectangle Area
Find the total area covered by two rectilinear rectangles in a2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the total a原创 2015-12-28 12:23:48 · 478 阅读 · 0 评论 -
【LEETCODE】136-Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2015-12-28 15:09:16 · 520 阅读 · 0 评论 -
【LEETCODE】260-Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums =原创 2015-12-28 16:00:10 · 528 阅读 · 0 评论 -
【LEETCODE】122-Best Time to Buy and Sell Stock II
Say you have an array for which the i th element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on原创 2015-12-28 17:36:24 · 511 阅读 · 0 评论 -
【LEETCODE】319-Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off原创 2015-12-28 18:11:33 · 2521 阅读 · 0 评论