![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
白雪忆青竹
低头也不失那绝世的帅气
展开
-
[leetcode] 49.Anagrams
题目:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case. 题意:给一个字符串数组,找出其中的所有的anagram组。anagram的意思是不同的单词但是含有相同的字符,这样的单词就称作anagram,比如veil,live,原创 2015-05-08 10:09:34 · 553 阅读 · 0 评论 -
[leetcode] 51.N-Queens
题目: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle.E原创 2015-05-08 23:06:30 · 280 阅读 · 0 评论 -
[leetcode] 53.Maximum Subarray
题目: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] ha原创 2015-05-09 10:17:52 · 323 阅读 · 0 评论 -
[leetcode] 56.Merge Intervals
题目: Given a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. 题意: 给一些区间,合并所有的有重合的区间。比如上面的例子,区间[1,3]与区间[2,6]有重合,那么原创 2015-05-09 16:48:55 · 267 阅读 · 0 评论 -
[leetcode] 57.Insert Interval
题目: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Examp原创 2015-05-09 18:12:41 · 375 阅读 · 0 评论 -
[leetcode] 60.Permutation Sequence
题目: The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3):“123” “132” “213” “231”原创 2015-05-09 22:36:59 · 347 阅读 · 0 评论 -
[leetcode] 52.N-Queens II
题目:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions. 题意:这道题与第51道题的不同是,这道题只需要返回一共有多少种可能,依旧采用回溯的方法来完成,只需要稍微改写第52道题的代码即可。 以上。原创 2015-05-09 09:30:24 · 367 阅读 · 0 评论 -
[leetcode] 54.Spiral Matrix
题目: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Y原创 2015-05-09 14:07:40 · 338 阅读 · 0 评论 -
[leetcode] 62.Unique Paths
题目: A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2015-05-10 16:06:04 · 328 阅读 · 0 评论 -
[leetcode] 55.Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are原创 2015-04-28 11:59:29 · 410 阅读 · 0 评论 -
[leetcode] 45.Jump Game II
问题描述: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is原创 2015-04-28 17:13:40 · 424 阅读 · 0 评论 -
[leetcode] 63.Unique Paths II
题目: Follow up for “Unique Paths”:Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid.F原创 2015-05-11 23:24:10 · 284 阅读 · 0 评论 -
[leetcode] 64.Minimum Path Sum
题目: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2015-05-11 23:42:36 · 322 阅读 · 0 评论 -
[leetcode] 67.Add Binary
题目: Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”. 题意: 给两个二进制数组的字符串,返回两者的和。 思路: 跟66题有些类似,也需要保存进位,需要考虑最高一位的进位情况。以上。代码如下:class Solut原创 2015-05-12 09:41:13 · 371 阅读 · 0 评论 -
[leetcode] 66.Plus One
题目: Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list. 题意: 将一个非负的整数按位放在一个数组里原创 2015-05-12 09:02:39 · 275 阅读 · 0 评论 -
[leetcode] 71.Simplify Path
题目: Given an absolute path for a file (Unix-style), simplify it.For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c” click to show corner cases.Corner Cases: Did you consider原创 2015-05-20 09:19:24 · 327 阅读 · 0 评论 -
[leetcode] 47.Permutations II
题目: For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], and [2,1,1]. 题意:这道题相对于第46道题的变化是数组里面会有重复出现的元素,所以结题思路需要稍微变化。 思路:比如[-1,2,0,-1,1,0,1]这样数组,我们考虑第一位上可以放的数据一共有-1,0,1,2这四原创 2015-05-07 22:22:33 · 357 阅读 · 0 评论 -
[leetcode] 68.Text Justification
题目: Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i原创 2015-05-12 13:18:09 · 344 阅读 · 0 评论 -
[leetcode] 46.Permutations
题目:Given a collection of numbers, return all possible permutations.For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. 题意是:给一个数字的集合,让你找出所有原创 2015-05-07 20:45:43 · 372 阅读 · 0 评论 -
[leetcode] 50.Pow(x, n)
题目:Implement pow(x, n). 题意:实现pow函数。 思路:这题需要做的是思考全面。在n=0时,直接返回1.在n>0时,直接让n个x相乘,当然n个x相乘的不需要o(n)的复杂度,只需要o(lgn)的复杂度,比如求100个2相乘,那么我们只要求得50个2相乘的结果,二分法只要o(lgn)复杂度。如果超过double的精度需要返回标记异常,比如面试官会让用一个全局变量记住。在原创 2015-05-08 10:31:39 · 374 阅读 · 0 评论 -
[leetode] 77.Combinations
题目: Given two integers n and k, return all possible combinations of k numbers out of 1 … n.For example, If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],原创 2015-06-19 10:29:13 · 318 阅读 · 0 评论 -
[leetcode] 88.Merge Sorted Array
题目: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit原创 2015-06-19 10:32:46 · 315 阅读 · 0 评论 -
[leetcode] 85.Maximal Rectangle
题目:Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing all ones and return its area. 题意:给一个二维的数组,数组里的元素是0或者1.找到包含元素全部是1的最大面积的数组。 分析:看到这道题的求最大面积会联想到上一道题,即84道题的求最大面积原创 2015-06-22 21:23:40 · 359 阅读 · 0 评论 -
[leetcode] 74.Search a 2D Matrix
题目: Write 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 integer of each r原创 2015-06-03 17:28:51 · 324 阅读 · 0 评论 -
[leetcode] 73.Set Matrix Zeroes
题目: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 题意: 给一个m x n的矩阵,如果某个元素是0,那么就将这个元素所在的行与这个元素所在的列都设为0. 思路: 这道题的一般思路是扫描所有元素,使用一个一维数组line[m]存储哪些行需要设为0,原创 2015-06-02 17:28:53 · 345 阅读 · 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’ -> 26Given an encoded message containing digits, determine the total numbe原创 2015-06-25 21:25:37 · 312 阅读 · 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? 题意: 你可以往上爬一个楼梯或者两格楼梯,到达顶端一共有n原创 2015-05-19 22:22:34 · 301 阅读 · 0 评论 -
[leetcode] 75.Sort Colors
题目: Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2015-06-04 15:35:21 · 329 阅读 · 0 评论 -
[leetcode] 93.Restore IP Addresses
题目: 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”]. (Order does原创 2015-06-25 22:35:42 · 393 阅读 · 0 评论 -
[leetcode] 69.Sqrt(x)
题目: mplement int sqrt(int x).Compute and return the square root of x. 题意: 实现一个求平方的函数,参数是一个整数,返回的也是一个整数。 思路: 这道题很明显的使用二分查找。需要考虑特殊情况,比如说x是最大的整数之类的。 代码参见以下:class Solution {public: int mySqrt(in原创 2015-05-19 22:15:44 · 288 阅读 · 0 评论 -
[leetcode] 89.Gray Code
题目: The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2015-06-25 14:28:51 · 352 阅读 · 0 评论 -
[leetcode] 96.Unique Binary Search Trees
题目: 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 1 \原创 2015-06-26 17:04:33 · 302 阅读 · 0 评论 -
[leetcode] 95.Unique Binary Search Trees II
题目: Given 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 below.1 3 3原创 2015-06-27 23:01:12 · 278 阅读 · 0 评论 -
[leetcode] 97.Interleaving String
题目: Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example, Given: s1 = “aabcc”, s2 = “dbbca”,When s3 = “aadbbcbcac”, return true. When s3 = “aadbbbaccc”, return原创 2015-06-28 00:08:55 · 293 阅读 · 0 评论 -
[leetcode] 100.Same Tree
题目: Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 题意: 给定两个二叉树原创 2015-06-26 15:54:24 · 319 阅读 · 0 评论 -
[leetcode] 98.Validate Binary Search Tree
题目: Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node’s key. The原创 2015-06-28 21:40:24 · 257 阅读 · 0 评论 -
[leetcode] 100.Recover Binary Search Tree
题目: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure. 题意: 二叉搜索树中有两个节点互换了位置,现在需要找出这两个节点来修复这个二叉搜索树。思路: 依旧依据搜索二叉树的顺序的性质,如果搜索二叉树是正确的,那么所原创 2015-06-28 22:47:29 · 315 阅读 · 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).For example: Given binary原创 2015-06-29 21:14:56 · 229 阅读 · 0 评论 -
[leetcode] 83.Remove Duplicates from Sorted List
题目: Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 比较简单就是删除相同的元素,代码如下:/*原创 2015-06-09 17:50:05 · 312 阅读 · 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. 题意: 给定一棵树的前序遍历以及中序遍历,构造出这棵树。 思路: 对于前序遍历,是先根再左右,对于中序遍历是原创 2015-06-30 15:48:54 · 265 阅读 · 0 评论