LeetCode
polar_geass
这个作者很懒,什么都没留下…
展开
-
LeetCode-51. N-Queens和LeetCode-52. N-Queens II
题意经典的八皇后问题,这里变成了N皇后,第一题是把所有情况列出来,第二题是求出解的个数。分析从问题上来看,第二问比第一问简单,所以我觉得应该把这两题的顺序颠倒一下,先做第二题。 1. 按行查找。假设搜索到了第i行,那么对于之前的所有行需要记录下它们各自放皇后的位置,所以需要一个数组来保存之前的每一行的列下标。 2. 对于第i行的j位置,要判断是否与之前所有的i-1行冲突,如...原创 2018-03-12 21:39:20 · 276 阅读 · 0 评论 -
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).原创 2017-12-25 14:40:07 · 98 阅读 · 0 评论 -
LeetCode-287. Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist.原创 2017-12-16 18:29:30 · 131 阅读 · 0 评论 -
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)原创 2017-12-07 09:23:51 · 94 阅读 · 0 评论 -
LeetCode-55. Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.原创 2017-11-28 09:47:47 · 95 阅读 · 0 评论 -
LeetCode-53. Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.原创 2017-11-27 18:44:57 · 177 阅读 · 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).原创 2017-12-24 10:39:26 · 106 阅读 · 0 评论 -
LeetCode-101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).原创 2017-12-23 17:20:53 · 127 阅读 · 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.原创 2017-12-06 13:23:58 · 103 阅读 · 0 评论 -
LeetCode-48. Rotate Image
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise).原创 2017-11-26 19:22:57 · 159 阅读 · 0 评论 -
LeetCode-283. Move Zeroes
Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.原创 2017-12-14 09:17:31 · 99 阅读 · 0 评论 -
LeetCode-85. Maximal Rectangle
Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.原创 2017-12-05 13:35:31 · 113 阅读 · 0 评论 -
LeetCode-98. Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).原创 2017-12-22 08:52:37 · 110 阅读 · 0 评论 -
LeetCode-94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes’ values.题目:树的中序遍历递归遍历原创 2017-12-21 09:46:08 · 109 阅读 · 0 评论 -
LeetCode-104. Maximum Depth of Binary Tree
Given 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.原创 2017-12-26 08:49:55 · 111 阅读 · 0 评论 -
LeetCode-108. Convert Sorted Array to Binary Search Tree
LeetCode-108. Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.原创 2017-12-26 19:14:15 · 140 阅读 · 0 评论 -
LeetCode-448. Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this array.原创 2017-12-18 16:52:38 · 141 阅读 · 0 评论 -
LeetCode-198. House Robber
You 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 adjacent house原创 2018-01-10 09:44:28 · 122 阅读 · 0 评论 -
LeetCode-12. Integer to Roman
题目Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.分析有关罗马数字的详细解释请参考 https://en.wikipedia.org/wiki/Roman_numerals 因为题目中明确指出输入范围是原创 2018-01-25 10:22:14 · 176 阅读 · 0 评论 -
LeetCode-139. Word Break
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. You may assu原创 2018-01-08 14:29:46 · 253 阅读 · 0 评论 -
LeetCode-322. Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money原创 2018-01-17 09:16:09 · 110 阅读 · 0 评论 -
LeetCode-91. Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given an encoded message containing digits, determine the原创 2018-01-08 08:36:39 · 147 阅读 · 0 评论 -
LeetCode-9. Palindrome Number
题目Determine whether an integer is a palindrome. Do this without extra space.题意输入:一个整数 输出:true或者false 判断这个整数是否是回文数,即将该整数反转后同原来相同。分析对于负整数而言,它没有回文数字,因为没有能对的上‘-’的字符;对于尾数为0的整数而言,只有当整数为0时才是回原创 2018-01-24 09:03:15 · 200 阅读 · 0 评论 -
LeetCode-70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a原创 2018-01-04 19:08:22 · 111 阅读 · 0 评论 -
LeetCode-230. Kth Smallest Element in a BST
Given 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.原创 2017-12-28 08:51:51 · 124 阅读 · 0 评论 -
LeetCode-124. Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.原创 2017-12-27 19:15:19 · 109 阅读 · 0 评论 -
LeetCode-44. Wildcard Matching
Implement wildcard pattern matching with support for ‘?’ and ‘*’.原创 2018-01-03 13:29:56 · 119 阅读 · 0 评论 -
LeetCode-279. Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n. For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13,原创 2018-01-12 08:37:08 · 183 阅读 · 0 评论 -
LeetCode-116. Populating Next Right Pointers in Each Node
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.原创 2017-12-27 08:40:57 · 104 阅读 · 0 评论 -
LeetCode-10. Regular Expression Matching
Implement regular expression matching with support for ‘.’ and ‘*’.原创 2018-01-02 13:48:18 · 127 阅读 · 0 评论 -
LeetCode-34. Search for a Range
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.原创 2017-11-24 23:56:04 · 158 阅读 · 0 评论 -
LeetCode-238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O(n)原创 2017-12-13 09:44:47 · 97 阅读 · 0 评论 -
LeetCode-84. Largest Rectangle in Histogram
LeetCode- Add to List 84. Largest Rectangle in Histogram原创 2017-08-19 13:38:59 · 285 阅读 · 0 评论 -
LeetCode-23. Merge k Sorted Lists
LeetCode-23. Merge k Sorted Lists原创 2017-08-24 10:59:58 · 136 阅读 · 0 评论 -
LeetCode-4. Median of Two Sorted Arrays
LeetCode-4. Median of Two Sorted Arrays原创 2017-08-22 17:24:11 · 182 阅读 · 0 评论 -
LeetCode-31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.原创 2017-11-19 23:21:12 · 120 阅读 · 0 评论 -
LeetCode-15. 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.原创 2017-11-19 20:29:50 · 147 阅读 · 0 评论 -
LeetCode-160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.原创 2017-11-14 17:14:07 · 112 阅读 · 0 评论 -
LeetCode-148. Sort List
Sort a linked list in O(n log n) time using constant space complexity.原创 2017-11-14 14:01:03 · 107 阅读 · 0 评论 -
LeetCode-142. Linked List Cycle II
LeetCode-142. Linked List Cycle II原创 2017-11-13 09:15:36 · 136 阅读 · 0 评论