- 博客(86)
- 收藏
- 关注
原创 leetcode[230]:Kth Smallest Element in a BST
Kth Smallest Element in a BSTGiven a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST’s total elements.Foll
2015-07-28 21:34:10 361
原创 leetcode[86]:Partition List
Partition ListGiven a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes i
2015-07-26 21:26:39 297
原创 leetcode[24]:Swap Nodes in Pairs
Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constan
2015-07-26 19:44:38 272
原创 leetcode[80]:Remove Duplicates from Sorted Array II
Remove Duplicates from Sorted Array IIFollow up for “Remove Duplicates“: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1,2,2,3],Your function should return
2015-07-26 19:35:42 304
原创 leetcode[109]:Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked list. * struct
2015-07-26 19:17:36 292
原创 leetcode[108]:Convert Sorted Array to Binary Search Tree
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for a binary tree node. * struct TreeNode {
2015-07-26 19:07:40 387
原创 leetcode[96]:Unique Binary Search Trees
Unique Binary Search TreesGiven 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
2015-07-26 18:25:12 298
原创 leetcode[199]:Binary Tree Right Side View
Binary Tree Right Side ViewGiven a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example: Given the followin
2015-07-26 17:55:42 281
原创 leetcode[103]:Binary Tree Zigzag Level Order Traversal
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
2015-07-26 17:02:16 365
原创 leetcode[117]:Populating Next Right Pointers in Each Node II
Populating Next Right Pointers in Each Node IIFollow 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 wor
2015-07-26 16:35:10 306
原创 leetcode[116]:Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each NodeGiven a binary treestruct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next;}Populate each next pointer to point to its next
2015-07-26 15:58:56 240
原创 leetcode[227]:Basic Calculator II
Basic Calculator II Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer di
2015-07-26 15:24:38 325
原创 leetcode[224]:Basic Calculator
Basic Calculator Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integ
2015-07-26 13:50:49 321
原创 leetcode[150]:Evaluate Reverse Polish Notation
Evaluate Reverse Polish NotationEvaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examp
2015-07-26 10:47:47 250
原创 !leetcode[162]:Find Peak Element
Find Peak ElementA peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple pe
2015-07-26 10:19:32 363
原创 leetcode[151]:Reverse Words in a String
这里写链接内容Given an input string, reverse the string word by word.For example, Given s = “the sky is blue”, return “blue is sky the”.Update (2015-02-12): For C programmers: Try to solve it in-place in O
2015-07-26 10:17:30 359
原创 leetcode[198]:House Robber
House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adj
2015-07-25 16:39:37 292
原创 leetcode[202]:Happy Number
Happy NumberWrite an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the
2015-07-25 16:01:14 247
原创 leetcode[205]:Isomorphic Strings
Isomorphic StringsGiven two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced
2015-07-25 15:36:30 260
原创 leetcode[137]:Single Number II
Single Number IIGiven 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
2015-07-25 14:27:44 279
原创 leetcode[136]:Single Number
Single NumberGiven 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 u
2015-07-25 12:45:29 224
原创 !leetcode[74&240]:Search a 2D Matrix I &II
Search a 2D MatrixWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:•Integers in each row are sorted from left to right. •The first in
2015-07-23 11:03:26 294
原创 leetcode[14]:Longest Common Prefix
Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.char* longestCommonPrefix(char** strs, int strsSize) { int i,j,flag=0; char *res;
2015-07-21 16:11:48 198
原创 leetcode[119]:Pascal's Triangle II
Pascal’s Triangle IIGiven 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? /
2015-07-21 10:44:27 267
原创 leetcode[118]:Pascal's Triangle
Pascal’s TriangleGiven 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]]/** * Return an
2015-07-21 10:13:09 271
原创 leetcode[94]:Binary Tree Inorder Traversal
Binary Tree Inorder TraversalGiven a binary tree, return the inorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive
2015-07-20 22:50:33 206
原创 leetcode[145]:Binary Tree Postorder Traversal
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: Re
2015-07-20 21:28:22 341
原创 leetcode[144]:Binary Tree Preorder Traversal
Binary Tree Preorder TraversalGiven 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].Note: Recursi
2015-07-20 20:15:58 248
原创 leetcode[107]:Binary Tree Level Order Traversal II
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: Giv
2015-07-20 14:37:50 224
原创 leetcode[102]:Binary Tree Level Order Traversal
Binary Tree Level Order TraversalGiven 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},
2015-07-19 22:09:03 313
原创 leetcode[236]:Lowest Common Ancestor of a Binary Tree
Lowest Common Ancestor of a Binary TreeGiven 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 ance
2015-07-19 14:52:01 250
原创 leetcode[235]:Lowest Common Ancestor of a Binary Search Tree
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: “Th
2015-07-19 14:17:39 272
原创 leetcode[20]:Valid Parentheses
Valid ParenthesesGiven a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” ar
2015-07-19 13:22:35 213
原创 leetcode[237]:Delete Node in a Linked List
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
2015-07-15 12:43:46 175
原创 leetcode[38]:Count and Say
Count and SayThe count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off a
2015-07-14 22:57:38 166
原创 leetcode[8]:String to Integer (atoi)
String to Integer (atoi) Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are t
2015-07-14 16:25:30 542
原创 leetcode[7]:Reverse Integer
Reverse IntegerReverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321click to show spoilers.Have you thought about this? Here are some good questions to ask before
2015-07-14 14:33:40 216
原创 leetcode[190]:Reverse Bits
Reverse BitsReverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00
2015-07-14 14:02:01 343
原创 leetcode[234]:Palindrome Linked List
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?/** * Definition for singly-linked list. * struct ListNode {
2015-07-14 11:09:21 257
原创 leetcode[125]:Valid Palindrome
Valid PalindromeGiven 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
2015-07-14 10:28:32 185
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人