LeetCode
XiaoM将故事
决定人生高度的从来都不是做事的完美程度,而是做事的速度.
展开
-
【Leetcode】36. Valid Sudoku
DescriptionDetermine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9 without repetition.Each colu...原创 2018-08-08 10:00:11 · 285 阅读 · 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...原创 2018-03-09 15:16:54 · 257 阅读 · 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?Suppose an array sorted in ascending order is rot...原创 2018-03-09 14:41:08 · 215 阅读 · 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 ...原创 2018-03-09 13:46:34 · 191 阅读 · 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原创 2018-03-09 11:16:39 · 170 阅读 · 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 permitted on a原创 2018-03-09 10:29:22 · 218 阅读 · 0 评论 -
leetcode 20. Valid Parentheses
题目Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all原创 2017-12-27 16:27:03 · 182 阅读 · 0 评论 -
leetcode 19. Remove Nth Node From End of List
题目Given a linked list, remove the nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end,原创 2017-12-27 16:25:12 · 183 阅读 · 0 评论 -
leetcode 18. 4Sum
题目Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solu原创 2017-12-27 15:00:24 · 184 阅读 · 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->...原创 2018-03-09 17:47:01 · 281 阅读 · 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 ...原创 2018-03-09 23:27:13 · 193 阅读 · 0 评论 -
【Leetcode】712. Minimum ASCII Delete Sum for Two Strings
DescriptionGiven two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal.Example 1:Input: s1 = "sea", s2 = "eat"Output: 231Explanation: Deleting "s" fro...原创 2018-08-08 00:45:18 · 292 阅读 · 0 评论 -
【Leetcode】646. Maximum Length of Pair Chain
DescriptionYou are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair (a, b) if and only if b &...原创 2018-08-09 12:44:17 · 256 阅读 · 0 评论 -
leetcode :Valid Palindrome
DescriptionGiven a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as valid palin...原创 2018-07-26 10:14:12 · 254 阅读 · 0 评论 -
leetcode 572.Subtree of Another Tree
题目Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this ...原创 2018-06-19 12:31:11 · 228 阅读 · 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.Example 1:Input: n = 12Output: 3 Explanation: 12 = 4 + 4 + 4....原创 2018-06-25 20:21:52 · 281 阅读 · 0 评论 -
leetcode 154. Find Minimum in Rotated Sorted Array II
题目 Follow up for “Find Minimum in Rotated Sorted Array”: What if duplicates are allowed? Would this affect the run-time complexity? How and why?Suppose an array sorted in ascending or...原创 2018-03-14 12:26:15 · 231 阅读 · 0 评论 -
Leetcode 118. Pascal's Triangle
题目Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]解法一class Solution...原创 2018-03-14 10:59:54 · 286 阅读 · 0 评论 -
leetcode 27. Remove Element
题目Given an array and a value, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array in-...原创 2018-03-14 10:04:51 · 189 阅读 · 0 评论 -
leetcode 17. Letter Combinations of a Phone Number
题目Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:原创 2017-12-27 11:19:33 · 261 阅读 · 0 评论 -
leetcode 16. 3Sum Closest
题目Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have e原创 2017-12-27 11:18:52 · 266 阅读 · 0 评论 -
leetcode 1. Tow Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the s原创 2017-12-22 08:24:53 · 217 阅读 · 0 评论 -
LeetCode 86.Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each原创 2017-10-11 10:55:29 · 194 阅读 · 0 评论 -
LeetCode 59. Spiral Matrix II
class Solution { public int[][] generateMatrix(int n) { int[][] a = new int[n][n]; int i = 0; int j = 0; int start = 0; while (i < n && j < n) {原创 2017-08-31 10:33:51 · 209 阅读 · 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原创 2017-09-07 18:33:10 · 183 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
public static int lengthOfLongestSubstring(String s) { int n = s.length(); int l = 0; int r = 0; int length = 0; Map map = new HashMap<>(); for (int i = 0; i < n; i++) { char c = s.c原创 2017-08-25 08:43:50 · 220 阅读 · 0 评论 -
LeetCode Minimum Factorization
public class Solution { int[] aa = new int[100]; int j = 0; boolean flag = true; public int smallestFactorization(int a) { smallest(a); Arrays.sort(aa); String string = ""; if(j > 31原创 2017-06-20 00:20:13 · 430 阅读 · 0 评论 -
LeetCode 347. Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number原创 2017-06-07 15:03:02 · 274 阅读 · 0 评论 -
LeetCode 404:Sum of Left Leaves
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Retur原创 2017-06-07 14:31:24 · 270 阅读 · 0 评论 -
leetcode 2. Add Two Numbers
题目:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and原创 2017-12-22 08:25:55 · 152 阅读 · 0 评论 -
leetcode 3. Longest Substring Without Repeating Characters
题目Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the原创 2017-12-22 08:28:00 · 191 阅读 · 0 评论 -
leetcode 11. Container With Most Water
题目Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin原创 2017-12-22 08:40:01 · 170 阅读 · 0 评论 -
leetcode 10. Regular Expression Matching
题目Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cove原创 2017-12-22 08:38:32 · 242 阅读 · 0 评论 -
leetcode 9. Palindrome Number
题目Determine whether an integer is a palindrome. Do this without extra space.解析class Solution { public boolean isPalindrome(int x) { if (x 0 || (x != 0 && x % 10 == 0)) {原创 2017-12-22 08:37:58 · 188 阅读 · 0 评论 -
leetcode 7. Reverse Integer
题目Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123 Output: 321 Example 2:Input: -123 Output: -321 Example 3:Input: 120 Output: 21 Note: Assume we ar原创 2017-12-22 08:37:09 · 203 阅读 · 0 评论 -
leetcode 6. ZigZag Conversion
题目The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H N A P L S原创 2017-12-22 08:36:28 · 230 阅读 · 0 评论 -
leetcode 5. Longest Palindromic Substring
题目Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a原创 2017-12-22 08:35:13 · 145 阅读 · 0 评论 -
leetcode 4. Median of Two Sorted Arrays
题目There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1: nums1 = [1, 3] n原创 2017-12-22 08:30:24 · 172 阅读 · 0 评论 -
LeetCode 120. Triangle
120. Triangle DescriptionHintsSubmissionsSolutionsTotal Accepted: 101928Total Submissions: 306497Difficulty: MediumContributor: LeetCodeGiven a triangle, find the minimum path sum from top原创 2017-05-28 23:23:22 · 407 阅读 · 0 评论