- 博客(28)
- 资源 (1)
- 收藏
- 关注
原创 【leetcode】排序算法
冒泡排序def bubble_sort(x): for i in range(len(x)): for j in range(1, len(x)-i): if x[j-1] > x[j]: x[j-1], x[j] = x[j], x[j-1] return x插入排序def insert_sor...
2018-11-08 11:22:11 542
原创 leetcode: 449. Serialize and Deserialize BST
DifficultyMedium.ProblemSerialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a ne...
2018-11-08 11:17:44 362
原创 leetcode: 215. Kth Largest Element in an Array
DifficultyMedium.ProblemFind 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.Example 1:Input: [3,2,1,5,6...
2018-11-08 11:16:00 341
原创 leetcode: 206. Reverse Linked List
DifficultyEasy.ProblemReverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLFollow up:A linked list can be reversed either ...
2018-11-08 11:14:21 330
原创 leetcode: 144. Binary Tree Preorder Traversal
DifficultyMedium.ProblemGiven a binary tree, return the preorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,2,3]Follow up: Recursive so...
2018-11-08 11:12:15 220
原创 leetcode: 141. Linked List Cycle
DifficultyEasy.ProblemGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?AC# Definition for singly-linked list.# class ListNode(objec...
2018-11-08 11:09:57 219
原创 leetcode: 122. Best Time to Buy and Sell Stock II
DifficultyEasy.ProblemSay you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions ...
2018-11-08 11:07:36 302
原创 leetcode: 129. Sum Root to Leaf Numbers
DifficultyEasy.ProblemSay you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions...
2018-11-08 11:01:33 237
原创 leetcode: 121. Best Time to Buy and Sell Stock
DifficultyEasy.ProblemSay you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sel...
2018-11-07 09:13:07 281
原创 leetcode: 120. Triangle
DifficultyMedium.ProblemGiven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ ...
2018-11-07 09:11:22 241
原创 leetcode: 119. Pascal's Triangle II
DifficultyEasy.ProblemGiven a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.Note that the row index starts from 0.In Pascal's triangle, each number is th...
2018-11-07 09:09:42 276
原创 leetcode: 118. Pascal's Triangle
DifficultyEasy.ProblemGiven a non-negative integer numRows, generate the first numRows of Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it.Ex...
2018-11-07 09:06:57 226
原创 leetcode: 117. Populating Next Right Pointers in Each Node II
DifficultyMedium.ProblemGiven a binary treestruct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next;}Populate each next pointer to point to its next right node. ...
2018-11-07 09:04:16 464
原创 leetcode: 116. Populating Next Right Pointers in Each Node
DifficultyMedium.ProblemGiven a binary treestruct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next;}Populate each next pointer to point to its next right node. I...
2018-11-07 09:02:28 353
原创 leetcode: 114. Flatten Binary Tree to Linked List [✗]
DifficultyMedium.ProblemGiven a binary tree, flatten it to a linked list in-place.For example, given the following tree: 1 / \ 2 5 / \ \3 4 6The flattened tree should look li...
2018-11-07 08:59:32 407
原创 leetcode: 113. Path Sum II
DifficultyMedium.ProblemGiven a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.Note: A leaf is a node with no children.Example:Given the below b...
2018-11-07 08:56:01 260
原创 leetcode: 112. Path Sum
DifficultyEasy.ProblemGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Note: A leaf is a node w...
2018-11-07 08:53:51 380
原创 leetcode: 111. Minimum Depth of Binary Tree
DifficultyEasy.ProblemGiven 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.Note: A leaf ...
2018-11-07 08:51:39 246
原创 leetcode: 110. Balanced Binary Tree
DifficultyEasy.ProblemGiven 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 ...
2018-11-05 17:13:29 241
原创 leetcode: 109. Convert Sorted List to Binary Search Tree
DifficultyMedium.ProblemGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as ...
2018-11-05 17:11:26 175
原创 leetcode: 108. Convert Sorted Array to Binary Search Tree
DifficultyEasy.ProblemGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree ...
2018-11-05 17:09:17 183
原创 leetcode: 107. Binary Tree Level Order Traversal II
DifficultyEasy.ProblemGiven 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 t...
2018-11-05 17:07:14 170
原创 leetcode: 106. Construct Binary Tree from Inorder and Postorder Traversal
DifficultyMedium.ProblemGiven inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, giveninorder = [9...
2018-11-05 17:03:30 189
原创 leetcode: 105. Construct Binary Tree from Preorder and Inorder Traversal
DifficultyMedium.ProblemGiven preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, givenpreorder = [3...
2018-11-05 17:01:10 243
原创 leetcode: 104. Maximum Depth of Binary Tree
DifficultyEasy.ProblemGiven 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.Note: A leaf ...
2018-11-05 16:58:17 209
原创 leetcode: 103. Binary Tree Zigzag Level Order Traversal
DifficultyMedium.ProblemGiven a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).Fo...
2018-11-05 16:45:59 188
原创 leetcode: 102. Binary Tree Level Order Traversal
DifficultyMedium.ProblemGiven 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,null,null,15,7...
2018-11-05 16:38:22 204
原创 leetcode: 101. Symmetric Tree
DifficultyEasy.Problem# Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).## For example, this binary tree [1,2,2,3,4,4,3] is symmetric:## 1# ...
2018-11-05 16:35:42 225
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人