![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCodec++刷题札记
AnonymousCrawler
Stay hungry, stay foolish.
展开
-
91. Decode Ways
Description:A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determi原创 2017-12-19 18:03:58 · 235 阅读 · 0 评论 -
103. Binary Tree Zigzag Level Order Traversal
Description: 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: G原创 2018-01-12 10:58:58 · 229 阅读 · 0 评论 -
7. Reverse Integer
Description:Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Not原创 2017-12-28 14:14:31 · 176 阅读 · 0 评论 -
9. Palindrome Number
Description:Determine whether an integer is a palindrome. Do this without extra space.分析:确定数字是否为回文数。将数字倒置,与原数一致即是回文数;否则,则不是。代码:class Solution {public: bool isPalindrome(int x) {原创 2017-12-28 15:00:40 · 190 阅读 · 0 评论 -
69. Sqrt(x)
Description:Implement int sqrt(int x).Compute and return the square root of x.x is guaranteed to be a non-negative integer.分析:这道题用二分法即可。易出错的地方是数是否越界的处理,我们取high(=x)如果x为INT_MAX的话,在high+low的操作就会造原创 2017-12-28 15:05:49 · 710 阅读 · 0 评论 -
105. Construct Binary Tree from Preorder and Inorder Traversal
Description: Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 分析:这道题是典型的分治问题。 eg.pre:[1,2,4,8,5,3,6,9,7], i原创 2018-01-13 13:23:36 · 298 阅读 · 0 评论 -
25. Reverse Nodes in k-Group
Description:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If原创 2017-12-30 02:05:30 · 294 阅读 · 0 评论 -
108. Convert Sorted Array to Binary Search Tree
Description:Given 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 in which th原创 2018-01-07 02:36:41 · 212 阅读 · 0 评论 -
110. Balanced Binary Tree
Description: 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原创 2018-01-07 03:31:34 · 558 阅读 · 0 评论 -
95. Unique Binary Search Trees II
Description:Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown原创 2018-01-09 18:42:20 · 221 阅读 · 0 评论 -
4. Median of Two Sorted Arrays
Descripition: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)).Example 1原创 2017-12-27 20:09:59 · 217 阅读 · 0 评论 -
102. Binary Tree Level Order Traversal
Description: 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,null,null,15,7], 3原创 2018-01-11 17:36:53 · 205 阅读 · 0 评论 -
82. Remove Duplicates from Sorted List II
Description:------------Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5原创 2017-12-18 13:23:21 · 217 阅读 · 0 评论 -
92. Reverse Linked List II
Description:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Give原创 2017-12-21 20:53:32 · 237 阅读 · 0 评论 -
93. Restore IP Addresses
Description: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"原创 2017-12-23 15:27:49 · 172 阅读 · 0 评论 -
142. Linked List Cycle II
Description:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using extra sp原创 2017-12-26 09:36:32 · 194 阅读 · 0 评论 -
71. Simplify Path
Description:Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:Did you consider the case翻译 2017-12-26 11:43:30 · 188 阅读 · 0 评论 -
143. Reorder List
Description:Given a singly linked list L: 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}, reor原创 2017-12-26 18:27:56 · 208 阅读 · 0 评论 -
41. First Missing Positive
Description:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3, and [3,4,-1,1] return 2。Your algorithm should run in O(n) time and uses原创 2018-01-01 22:58:35 · 268 阅读 · 0 评论 -
90. Subsets II
Description:Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.For原创 2017-12-18 22:21:30 · 249 阅读 · 0 评论 -
86. Partition List
Description:Given 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原创 2017-12-18 17:12:32 · 312 阅读 · 0 评论 -
96. Unique Binary Search Trees
Description: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原创 2018-01-09 16:52:59 · 192 阅读 · 0 评论