leetcode
moli2333
这个作者很懒,什么都没留下…
展开
-
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.For example, given the following matrix:1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0原创 2016-09-28 15:17:03 · 220 阅读 · 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 is,原创 2016-09-22 11:22:47 · 200 阅读 · 0 评论 -
leetcode 67. Add Binary
Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”.public String addBinary(String a, String b) { int inta = Integer.parseInt(a, 2);原创 2016-09-21 12:17:19 · 373 阅读 · 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.13: int[]{1,3} 27: int[]{2原创 2016-09-21 11:54:13 · 168 阅读 · 0 评论 -
leetcode 65. Valid Number
Validate if a given string is numeric.Some examples: “0” => true ” 0.1 ” => true “abc” => false “1 a” => false “2e10” => true Note: It is intended for the problem statement to be ambiguous. You s原创 2016-09-21 11:09:51 · 359 阅读 · 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 any原创 2016-09-21 10:19:21 · 160 阅读 · 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.For ex原创 2016-09-21 10:06:17 · 210 阅读 · 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 botto原创 2016-09-20 22:42:12 · 169 阅读 · 0 评论 -
leetcode 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. 需要两个指针 一个j指向5一个i指向3 所以起始的时候i指向1 j指向3原创 2016-09-20 21:27:03 · 404 阅读 · 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” “312”原创 2016-09-19 22:10:58 · 222 阅读 · 0 评论 -
leetcode 59. Spiral Matrix II
之前那道题目是螺旋读矩阵 这道是螺旋写入矩阵public int[][] generateMatrix(int n) { int[][] result = new int[n][n]; int temp = 1; for(int i = 0;i < (n+1)/2 && i < (n+1)/2 ;i++){//[i,i]为起点走一圈原创 2016-09-19 21:04:47 · 204 阅读 · 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 0, 1,原创 2016-09-22 17:18:52 · 344 阅读 · 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 row is原创 2016-09-22 16:35:15 · 192 阅读 · 0 评论 -
leetcode 69. Sqrt(x)
public int mySqrt(int x) { return (int)Math.sqrt(x); } A了就不想想了原创 2016-09-22 14:44:24 · 230 阅读 · 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?public int climbStairs(int n) {原创 2016-09-22 14:49:01 · 171 阅读 · 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 the原创 2016-09-22 15:25:27 · 267 阅读 · 0 评论 -
leetcode 84. Largest Rectangle in Histogram
Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each bar原创 2016-09-28 10:45:20 · 195 阅读 · 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.public ListNode deleteDuplicates原创 2016-09-27 17:17:34 · 194 阅读 · 0 评论 -
leetcode 82. Remove Duplicates from Sorted List II
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, return 1->2->5. Given 1->1->1->2原创 2016-09-27 17:12:22 · 228 阅读 · 0 评论 -
leetcode 81. Search in Rotated Sorted Array II
Follow up for “Search in Rotated Sorted Array”: What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the array.回顾原创 2016-09-27 15:32:35 · 202 阅读 · 0 评论 -
leetcode 33. Search in Rotated Sorted Array __java
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its index原创 2016-09-10 21:34:26 · 231 阅读 · 0 评论 -
leetcode 80. Remove Duplicates from Sorted Array II
Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first five elemen原创 2016-09-27 15:26:34 · 306 阅读 · 0 评论 -
leetcode 79. Word Search
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, where “adjacent” cells are those horizontally or vertically neig原创 2016-09-27 14:51:56 · 496 阅读 · 0 评论 -
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], [2],原创 2016-09-27 13:54:40 · 261 阅读 · 0 评论 -
leetcode 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], ]pu原创 2016-09-26 23:52:01 · 176 阅读 · 0 评论 -
leetcode 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 “BANC”.Note:原创 2016-09-26 19:14:44 · 271 阅读 · 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.click to show follow up.Follow up: Did you use extra space? A straight forward solution using O(mn) space原创 2016-09-22 16:22:15 · 232 阅读 · 0 评论 -
leetcode 72. Edit Distance
去爱奇艺面实习岗的时候问的这个 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 have the following 3 operations permitte原创 2016-09-22 16:08:14 · 175 阅读 · 0 评论 -
leetcode 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 defined as原创 2016-09-19 20:49:06 · 159 阅读 · 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.Example 1:原创 2016-09-19 20:38:47 · 162 阅读 · 0 评论 -
leetcode 41. First Missing Positive
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 constant space.时间原创 2016-09-13 16:17:25 · 133 阅读 · 0 评论 -
leetcode 39. Combination Sum
“C++程序员觉得内存管理太重要了,所以一定要自己进行管理;Java/C#程序员觉得内存管理太重要了,所以一定不能自己去管理。” 简直人生态度。 Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers su原创 2016-09-13 10:30:10 · 164 阅读 · 0 评论 -
leetcode 40. Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combination.No原创 2016-09-13 15:42:12 · 175 阅读 · 0 评论 -
leetcode 圆桌红包(美团点评)
题目描述:圆桌上有N个红包,金额不等(也有可能部分相等),不能拿相邻的两个,问能拿到的最大金额是多少? 在这道题目之前首先复习一下我对递归和动态规划的印象: 分治法:将大问题转化为小问题的思想 递归:从上往下(从大到小) 动态规划:从底往上(从小到大)场景一:分治:f(n) = f(n -1)+1递归: f(int n ){ if(n == 1)原创 2016-09-13 10:14:03 · 505 阅读 · 0 评论 -
leetcode 38. Count and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “one 2, the原创 2016-09-12 15:16:59 · 151 阅读 · 0 评论 -
leetcode 37. Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character ‘.’.You may assume that there will be only one unique solution. 啊,是上一题的扩展 很快有了一个思路原创 2016-09-12 11:33:52 · 142 阅读 · 0 评论 -
leetcode 36. Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’.A partially filled sudoku which原创 2016-09-12 11:05:19 · 203 阅读 · 0 评论 -
leetcode 35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here原创 2016-09-12 10:51:30 · 136 阅读 · 0 评论 -
leetcode 34. Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If the target is not found in the ar原创 2016-09-12 09:46:21 · 137 阅读 · 0 评论 -
leetcode 32. Longest Valid Parentheses __ java
Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring. 给定字符串只包含左右括号 求格式规范的子串最长长度 For “(()”, the longest valid parentheses原创 2016-09-10 19:18:09 · 215 阅读 · 0 评论