![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 76
xiao_dondon
每天进步一点点
展开
-
LeetCode-79
给定一个二维网格和一个单词,找出该单词是否存在于网格中。单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。示例:board =[ ['A','B','C','E'], ['S','F','C','S'], ['A','D','E','E']]给定 word = "ABCCE...原创 2019-05-23 00:03:04 · 176 阅读 · 0 评论 -
179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve原创 2017-08-11 23:27:52 · 180 阅读 · 0 评论 -
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原创 2017-08-18 15:35:26 · 158 阅读 · 0 评论 -
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""3原创 2017-08-11 00:18:53 · 193 阅读 · 0 评论 -
58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2017-08-10 16:20:17 · 175 阅读 · 0 评论 -
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.E原创 2017-08-10 15:51:14 · 193 阅读 · 0 评论 -
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原创 2017-08-17 13:44:00 · 194 阅读 · 0 评论 -
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].题意:给定若干区间,要求我们把有交错或者相邻的区间合并。如上例子;这个题的思路是:先把区间按照起始位置s原创 2017-08-09 16:02:11 · 225 阅读 · 0 评论 -
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*n的矩阵,如果某个元素为0,那么改行该列的元素皆改为0.要求在原矩阵上操作。我的第一想法是,定义2个boolean数组,用来记录改行或者该列是否存在0元素,然后根据boolean数组的原创 2017-08-16 15:52:28 · 314 阅读 · 0 评论 -
50. Pow(x, n)
Implement pow(x, n).题目求x的n次方,n可以为正、负、零。最简单的思路,递归或者循环z原创 2017-08-05 10:36:05 · 254 阅读 · 0 评论 -
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.Eac原创 2017-08-06 19:41:12 · 276 阅读 · 0 评论 -
525. Contiguous Array
Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.Example 1:Input: [0,1]Output: 2Explanation: [0, 1] is the longest contiguous subarray with原创 2017-08-24 12:29:06 · 271 阅读 · 0 评论 -
69. Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.题意:求x的平方根。直接看代码:public class Solution { public int mySqrt(int x) { if(x == 0) return 0; if原创 2017-08-15 21:53:40 · 250 阅读 · 0 评论 -
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],]原创 2017-08-22 16:13:16 · 20951 阅读 · 0 评论 -
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原创 2017-08-15 16:01:15 · 185 阅读 · 0 评论 -
67. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".题意:给定2个字符串,代表2个二进制数,求这2个数相加得到的字符串。直接看代码:public class Solution { public S原创 2017-08-15 13:31:54 · 221 阅读 · 0 评论 -
66. Plus One
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digi原创 2017-08-14 22:53:49 · 296 阅读 · 0 评论 -
76. Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN原创 2017-08-21 16:01:40 · 332 阅读 · 0 评论 -
52. N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.这是n皇后问题的第二种问题形式,我们在上一题中将所有放置皇后的方式都找了出来并存储在集合中,现在,我们问题貌似变得简单了,只需要计算出总共有多原创 2017-08-06 21:09:31 · 382 阅读 · 0 评论 -
71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"题意:给定一个绝对路径,要求我们简化这个路径。我们先简单的介绍一下绝对路径的一些特点:.表示当前文件原创 2017-08-16 15:16:20 · 182 阅读 · 0 评论 -
405. Convert a Number to Hexadecimal
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.题意:将一个十进制数转化成16进制。题目很简单,如果要转化的树是正数,那么用它除16取余即可。对于负数,先转化成二进制补码,然后在进行转化原创 2017-06-03 22:10:58 · 208 阅读 · 0 评论 -
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 yo原创 2017-08-08 16:03:50 · 162 阅读 · 0 评论 -
61. Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.题意:将列表右边的k个元素旋转到链表前面。需要注意的一原创 2017-05-28 21:40:51 · 174 阅读 · 0 评论 -
59. Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [原创 2017-05-28 23:26:52 · 185 阅读 · 0 评论 -
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-05-26 12:34:54 · 202 阅读 · 0 评论 -
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], [原创 2017-05-25 19:59:29 · 183 阅读 · 0 评论 -
123. Best Time to Buy and Sell Stock III
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 at most two transactions.Note:You ma原创 2017-05-26 13:55:50 · 207 阅读 · 0 评论 -
115. Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non原创 2017-05-25 16:42:34 · 287 阅读 · 0 评论 -
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", r原创 2017-05-24 16:00:53 · 159 阅读 · 0 评论 -
96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?题意:给定整数n,计算出这1~n个整数能组成多少二叉查找树。此题要做的事情跟上一题是一样的,只是要求的内容不同。大家可以先参考我上一题的思路 点击打开链接利用上一题的方法中得到的List求size就原创 2017-05-23 21:12:48 · 219 阅读 · 0 评论 -
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原创 2017-05-30 15:19:51 · 166 阅读 · 0 评论 -
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原创 2017-06-02 23:19:15 · 194 阅读 · 0 评论 -
49. Group Anagrams
Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]Note: Al原创 2017-08-01 00:42:13 · 199 阅读 · 0 评论 -
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 ]]You原创 2017-08-07 23:23:31 · 188 阅读 · 0 评论 -
48. Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?题目:顺时针旋转一个n*n的二维数组90度我们在草稿上先分析一下,我们要把a[n][0]旋原创 2017-07-31 10:42:43 · 173 阅读 · 0 评论 -
46(47). Permutations
Given a collection of distinct numbers, return all possible permutations.求无重复元素集合的全排列。这是一道比较经典的题目,面试过程中碰到的次数也比较多。我们的第一想法就是使用递归求解,假设我们要求n个元素的全排列,我们可以先从这n个元素中循环取出其中1个元素,然后只需要求剩下的n-1个元素的全排列即可,……,如此原创 2017-07-30 16:33:08 · 166 阅读 · 0 评论 -
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 i原创 2017-07-29 16:12:16 · 295 阅读 · 0 评论 -
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 \原创 2017-05-30 21:31:53 · 330 阅读 · 0 评论 -
598. Range Addition II
Given an m * n matrix M initialized with all 0's and several update operations.Operations are represented by a 2D array, and each operation is represented by an array with two positive integers a原创 2017-05-30 21:57:23 · 381 阅读 · 0 评论 -
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原创 2017-06-02 19:59:55 · 215 阅读 · 0 评论