- 博客(61)
- 收藏
- 关注
原创 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 solut
2015-08-31 22:22:00 271
原创 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
2015-08-31 22:12:13 245
原创 Leetcode #137 Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u
2015-08-31 22:00:20 243
原创 Leetcode # 169 Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element
2015-08-31 09:21:10 235
原创 Leetcode #37 Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku
2015-08-31 08:59:33 192
原创 Leetcode #217 Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element
2015-08-31 05:19:13 272
原创 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].Difficulty: Medium学习到了
2015-08-30 11:01:59 199
原创 Leetcode #171 Excel Sheet Column Number
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...
2015-08-30 10:41:17 211
原创 Leetcode #133 Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for ea
2015-08-30 10:31:12 251
原创 Leetcode #141 Linked List Cycle Python
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Difficulty:Medium不占用额外地址的做法,两个node一个每次跳一次,一个每次跳两下next,如果碰到none就返回False,如果这个两个nod
2015-08-29 01:44:53 412
原创 Leetcode #226 Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Difficulty: Easy# Definition for a binary tree node.# class Tree
2015-08-28 23:47:52 298
原创 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 betw
2015-08-28 04:28:10 195
原创 Leetcode #191 Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000
2015-08-28 04:25:48 232
原创 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 val
2015-08-27 11:13:57 223
原创 Leetcode 258 258
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 on
2015-08-27 11:11:50 287
原创 Leetcode #130 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 X
2015-08-25 08:22:26 228
原创 Leetcode #131 Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","
2015-08-25 05:03:04 257
原创 Leetcode #4 Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Difficulty:Hard看似比较简单的一
2015-08-13 19:25:54 172
原创 Leetcode #242 Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may a
2015-08-13 15:43:57 180
原创 Leetcode #129 Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota
2015-08-13 01:22:53 168
原创 Leetcode# 125 Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a
2015-08-13 00:37:51 190
原创 Leetcode# 122 Best Time to Buy and Sell Stock II
Say 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 as you like (ie, buy on
2015-08-11 19:15:09 249
原创 Leetcode #121 Best Time to Buy and Sell Stock
Say 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 (ie, buy one and sell one share of the stock),
2015-08-11 19:14:10 249
原创 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.Difficulty:Easy/** * Definiti
2015-08-11 18:09:00 221
原创 Leetcode #120 Triangle
Given 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[ [2], [3,4], [
2015-08-11 17:51:36 220
原创 Leetcode #119 Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?Difficulty:E
2015-08-11 02:52:11 234
原创 Leetcode #118 Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Difficulty:Easyclass Sol
2015-08-11 02:49:41 253
原创 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
2015-08-11 02:47:12 266
原创 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.
2015-08-11 02:42:06 206
原创 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-08-09 19:58:11 222
原创 Leetcode #113 Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \
2015-08-09 19:10:07 257
原创 Leetcode# 112 Path Sum
Given 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.For example:Given the below binary tree and sum
2015-08-09 18:56:02 218
原创 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 of every node never diffe
2015-08-09 18:18:00 212
原创 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 e
2015-08-09 00:48:03 208
原创 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.Difficulty:MediumTreeNode* sortedListToBST(ListNode* head) { TreeNode* root;
2015-08-08 16:43:36 246
原创 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.Difficulty:MediumTreeNode* build(vector& nums, int start, int end){ int mid = (end+start)/2
2015-08-08 16:08:03 219
原创 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-08-08 14:45:01 254
原创 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.Difficulty:Medium/** * Definition for a binary tree
2015-08-08 03:42:58 222
原创 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 treeDifficulty:Medium/** * Definition for a binary tr
2015-08-08 03:40:37 194
原创 Leetcode # 103 Binary Tree Zigzag Level Order Traversal
Given 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).For example:Given binary
2015-08-08 00:21:29 217
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人