Java 【 LeetCode】79. Word Search 问题描述 https://leetcode.com/problems/word-search/#/description Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell,
Java 【LeetCode】78. Subsets 问题描述 Given a set of distinct integers, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example, If nums = [1,2,3], a solution is: [ [3], [1]
Java 【LeetCode】77. Combinations 问题描述 https://leetcode.com/problems/combinations/#/description 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
Java 【LeetCode】75. Sort Colors 问题描述 https://leetcode.com/problems/sort-colors/#/description 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
Java 【LeetCode】74. Search a 2D Matrix 问题描述 https://leetcode.com/problems/search-a-2d-matrix/#/description 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
Java 【LeetCode】 73. Set Matrix Zeroes 问题描述 https://leetcode.com/problems/set-matrix-zeroes/#/description Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 给定一个矩阵,如果一个元素为0,则其所在行和所在列都置为0.
Java 【LeetCode】72. Edit Distance 问题描述 https://leetcode.com/problems/edit-distance/#/description Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You
Java 【LeetCode】71. Simplify Path 问题描述 https://leetcode.com/problems/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
Java 【LeetCode】69. Sqrt(x) 问题描述 https://leetcode.com/problems/sqrtx/#/description Implement int sqrt(int x). Compute and return the square root of x. 算法 使用折半查找即可,但要注意整型溢出 代码 public int mySqrt(int x) { int left = 1, right
Java 【LeetCode】68. Text Justification 问题描述 https://leetcode.com/problems/text-justification/#/description 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)
Java 【LeetCode】64. Minimum Path Sum 问题描述 https://leetcode.com/problems/minimum-path-sum/#/description 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
Java 【LeetCode】63. Unique Paths II 问题描述 https://leetcode.com/problems/unique-paths-ii/#/description 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
Java 【LeetCode】62. Unique Paths 问题描述 https://leetcode.com/problems/unique-paths/#/description 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
Java 【LeetCode】60. Permutation Sequence 问题描述 https://leetcode.com/problems/permutation-sequence/#/description he 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
Java 【LeetCode】59. Spiral Matrix II 问题描述 https://leetcode.com/problems/spiral-matrix-ii/#/description Given an integer n, generate a square matrix filled with elements from 1 to n^2 in spiral order. For example, Given n = 3, You should
Java 【LeetCode】57. Insert Interval 问题描述 https://leetcode.com/problems/insert-interval/#/description 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
Java 【LeetCode】56. Merge Intervals 问题描述 https://leetcode.com/problems/merge-intervals/#/description 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,
Java 【LeetCode】55. Jump Game 问题描述 https://leetcode.com/problems/jump-game/#/description 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
Java 【LeetCode】54. Spiral Matrix 问题描述 https://leetcode.com/problems/spiral-matrix/#/description 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
Java 【LeetCode】53. Maximum Subarray 问题描述 https://leetcode.com/problems/maximum-subarray/#/description 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,
Java 【LeetCode】52. N-Queens II 问题描述 https://leetcode.com/problems/n-queens-ii/#/description Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions. 比N-Queens [http://www.zgljl2012.com/leetcode-51-n-queens/] 反倒容易一点了,因为不需要存储解法,只需要计算数目。
Java 【LeetCode】51. N-Queens 问题描述 https://leetcode.com/problems/n-queens/#/description 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
Java 【LeetCode】50. Pow(x, n) 问题描述 https://leetcode.com/problems/powx-n/#/description Implement pow(x, n). 实现pow(x,n),及实现幂运算。 算法分析 这个题目的难度是中等,所以如果用显而易见的那个O(n)算法,即直接循环n次,将n个x乘起来的话是肯定会超时的,所以,只能用递归分治算法,即一次只乘一半,设值为A ,即当n为偶数时,结果是A*A;当n为奇数时,结果为A*A*x;
Java 【LeetCode】49. Group Anagrams 问题描述 https://leetcode.com/problems/anagrams/#/description 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: All
Java 【LeetCode】48. Rotate Image 问题描述 https://leetcode.com/problems/rotate-image/#/description 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?