
LeetCode算法题目
文章平均质量分 66
tomyleee
中山大学数据科学与计算机学院2015级软件工程
https://github.com/Tomy-Lee
http://tomylijia.com
展开
-
[LeetCode-Algorithms-517] "Super Washing Machines" (2018.1.8-WEEK19)
题目链接:Super Washing Machines 题目描述: You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty. For each move, you could choose any m (1 ≤ m ≤ n)原创 2018-01-08 22:02:03 · 292 阅读 · 0 评论 -
[LeetCode-Algorithms-49] "Group Anagrams" (2017.11.21-WEEK12)
题目链接:Group Anagrams 题目描述: Given an array of strings, group anagrams together. For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return: [ ["ate", "eat","tea"], ["n原创 2017-11-21 21:28:18 · 177 阅读 · 0 评论 -
[LeetCode-Algorithms-19] "Remove Nth Node From End of List" (2017.11.16-WEEK11)
题目链接: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.原创 2017-11-16 10:25:49 · 280 阅读 · 0 评论 -
[LeetCode-Algorithms-48] "Rotate Image" (2017.11.16-WEEK11)
题目链接:Rotate Image 题目描述: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, which means y原创 2017-11-16 10:04:08 · 157 阅读 · 0 评论 -
[LeetCode-Algorithms-39] "Combination Sum" (2017.11.29-WEEK13)
题目链接:Combination Sum 题目描述: Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same原创 2017-11-29 11:24:53 · 162 阅读 · 0 评论 -
[LeetCode-Algorithms-40] "Combination Sum II" (2017.11.29-WEEK13)
题目链接: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 ma原创 2017-11-29 11:00:25 · 164 阅读 · 0 评论 -
[LeetCode-Algorithms-50] "Pow(x, n)" (2017.10.25-WEEK8)
题目链接:Pow(x, n) 题目描述: Implement pow(x, n). (1)思路:分情况先把结果最简单的一些情况输出,然后使用分治将问题转化为两个 pow(x*x, n / 2)相乘,然后递归调用直到最后刚好乘完或者剩余一项(正或者负)。(2)代码:class Solution {public: double myPow(double x, int原创 2017-10-25 23:01:31 · 155 阅读 · 0 评论 -
[LeetCode-Algorithms-22] "Generate Parentheses" (2017.10.25-WEEK8)
题目链接:Generate Parentheses 题目描述: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ “(原创 2017-10-25 22:38:15 · 149 阅读 · 0 评论 -
[LeetCode-Algorithms-654] "Maximum Binary Tree" (2017.9.8)
题目链接:Maximum Binary Tree 题目描述: Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: The root is the maximum number in the array. The left原创 2017-09-08 22:33:04 · 219 阅读 · 0 评论 -
[LeetCode-Algorithms-20] "Valid Parentheses" (2017.11.1-WEEK9)
题目链接: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 ()[原创 2017-11-01 23:13:04 · 162 阅读 · 0 评论 -
[LeetCode-Algorithms-62] "Unique Paths" (2017.11.21-WEEK12)
题目链接: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原创 2017-11-21 23:05:43 · 186 阅读 · 0 评论 -
[LeetCode-Algorithms-147] "Insertion Sort List" (2017.12.21-WEEK16)
题目链接:Insertion Sort List 题目描述: Sort a linked list using insertion sort. (1)思路:将链表分为两部分,前半部分为已经排序好的,后半部分是未排序的,用指针指向未排序的头结点,遍历已经排序的部分,找到第一个大于该值的节点,然后将其插入到该节点之前一个位置即可;未排序部分的头结点向后移一个节点即可,直至遍历完原创 2017-12-21 10:58:05 · 202 阅读 · 0 评论 -
[LeetCode-Algorithms-223] "Rectangle Area" (2018.1.1-WEEK18)
题目链接:Rectangle Area 题目描述: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the fig原创 2018-01-01 22:14:34 · 227 阅读 · 0 评论 -
[LeetCode-Algorithms-216] "Combination Sum III" (2018.1.1-WEEK18)
题目链接:Combination Sum III题目描述: Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of num原创 2018-01-01 22:04:55 · 202 阅读 · 0 评论 -
[LeetCode-Algorithms-73] "Set Matrix Zeroes" (2017.12.26-WEEK17)
题目链接: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. Did you use extra space? A straight forward solution using O(mn)原创 2017-12-26 14:51:25 · 212 阅读 · 0 评论 -
[LeetCode-Algorithms-89] "Gray Code" (2017.12.26-WEEK17)
题目链接: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 c原创 2017-12-26 14:31:24 · 203 阅读 · 0 评论 -
[LeetCode-Algorithms-537] "Complex Number Multiplication" (2017.12.7-WEEK14)
题目链接:Complex Number Multiplication 题目描述: Given two strings representing two complex numbers. You need to return a string representing their multiplication. Note i2 = -1 according to the defin原创 2017-12-07 19:23:48 · 163 阅读 · 0 评论 -
[LeetCode-Algorithms-75] "Sort Colors" (2017.12.7-WEEK14)
题目链接: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. He原创 2017-12-07 19:04:13 · 158 阅读 · 0 评论 -
[LeetCode-Algorithms-128] "Longest Consecutive Sequence" (2017.12.14-WEEK15)
题目链接:Longest Consecutive Sequence 题目描述: Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2],原创 2017-12-14 13:42:32 · 249 阅读 · 0 评论 -
[LeetCode-Algorithms-139] "Word Break" (2017.12.14-WEEK15)
题目链接:Word Break 题目描述: Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dicti原创 2017-12-14 13:25:10 · 200 阅读 · 0 评论 -
[LeetCode-Algorithms-144] "Binary Tree Preorder Traversal" (2017.12.21-WEEK16)
题目链接: 题目描述: Given a binary tree, return the preorder traversal of its nodes’ values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,2,3].原创 2017-12-21 11:28:44 · 199 阅读 · 0 评论 -
[LeetCode-Algorithms-65] "Valid Number" (2017.11.1-WEEK9)
题目链接: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 s原创 2017-11-01 22:51:29 · 178 阅读 · 0 评论 -
[LeetCode-Algorithms-647] "Palindromic Substrings" (2017.11.7-WEEK10)
题目链接:Palindromic Substrings 题目描述: Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are counted原创 2017-11-07 20:44:22 · 156 阅读 · 0 评论 -
[LeetCode-Algorithms-24] "Swap Nodes in Pairs" (2017.11.7-WEEK10)
题目链接:Swap Nodes in Pairs 题目描述: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your a原创 2017-11-07 20:34:14 · 177 阅读 · 0 评论 -
[LeetCode-Algorithms-6] "ZigZag Conversion" (2017.9.28-WEEK4)
题目链接: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 legibil原创 2017-09-28 19:25:50 · 175 阅读 · 0 评论 -
[LeetCode-Algorithms-42] "Trapping Rain Water" (2017.9.28-WEEK4)
题目链接:Trapping Rain Water 题目描述: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For examp原创 2017-09-28 19:13:48 · 161 阅读 · 0 评论 -
[LeetCode-Algorithms-1] "Two Sum" (2017.9.8)
题目链接:Two 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, an原创 2017-09-08 20:54:06 · 252 阅读 · 0 评论 -
[LeetCode-Algorithms-3] "Longest Substring Without Repeating Characters" (2017.9.8)
题目链接:Longest Substring Without Repeating Characters 题目描述: Given a string, find the length of the longest substring without repeating characters. Examples: Given “abcabcbb”, the answer i原创 2017-09-08 21:47:36 · 194 阅读 · 0 评论 -
[LeetCode-Algorithms-13] "Roman to Integer" (2017.9.22-WEEK3)
题目链接:Roman to Integer 题目描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.(1)思路:这个问题比较简单,首先要搞清楚罗马数字的表达方式,然后对应的把四位表示用数组列举出来,然后由数据范原创 2017-09-22 19:36:31 · 179 阅读 · 0 评论 -
[LeetCode-Algorithms-23] "Merge k Sorted Lists" (2017.9.22-WEEK3)
题目链接:Merge k Sorted Lists 题目描述: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. (1)思路:设置一个表示首最小值的变量,已经一个记录最小值位置的变量,然后循环整个lists,找到已经排好序的li原创 2017-09-22 19:25:26 · 211 阅读 · 0 评论 -
[LeetCode-Algorithms-30] "Substring with Concatenation of All Words" (2017.9.22-WEEK3)
题目链接:Substring with Concatenation of All Words 题目描述: You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that i原创 2017-09-22 19:07:31 · 186 阅读 · 0 评论 -
[LeetCode-Algorithms-9] "Palindrome Number" (2017.9.14-WEEK2)
题目链接:Palindrome Number 题目描述: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinki原创 2017-09-14 14:40:45 · 180 阅读 · 0 评论 -
[LeetCode-Algorithms-8] "String to Integer (atoi)" (2017.9.14-WEEK2)
题目链接:String to Integer (atoi) 题目描述: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask原创 2017-09-14 14:23:56 · 171 阅读 · 0 评论 -
[LeetCode-Algorithms-25] "Reverse Nodes in k-Group" (2017.9.28-WEEK4)
题目链接:Reverse Nodes in k-Group 题目描述: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the原创 2017-09-28 19:39:26 · 205 阅读 · 0 评论 -
[LeetCode-Algorithms-14] "Longest Common Prefix" (2017.10.2-WEEK5)
题目链接:Longest Common Prefix 题目描述: Write a function to find the longest common prefix string amongst an array of strings. (1)思路:这个题就是直接逐个字符比较,时间复杂度O(N*L)。(2)代码:class Solution {public: s原创 2017-10-02 10:12:35 · 184 阅读 · 0 评论 -
[LeetCode-Algorithms-55] "Jump Game" (2017.11.7-WEEK10)
题目链接: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 th原创 2017-11-07 20:20:19 · 181 阅读 · 0 评论 -
[LeetCode-Algorithms-26] "Remove Duplicates from Sorted Array" (2017.10.12-WEEK6)
题目链接:Remove Duplicates from Sorted Array 题目描述: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra sp原创 2017-10-12 21:10:58 · 177 阅读 · 0 评论 -
[LeetCode-Algorithms-10] "Regular Expression Matching" (2017.10.12-WEEK6)
题目链接:Regular Expression Matching 题目描述: Implement regular expression matching with support for ‘.’ and ‘*’. ‘.’ Matches any single character. ‘*’ Matches zero or more of the precedin原创 2017-10-12 21:03:07 · 231 阅读 · 0 评论 -
[LeetCode-Algorithms-17] "Letter Combinations of a Phone Number" (2017.10.12-WEEK6)
题目链接: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原创 2017-10-12 20:47:02 · 211 阅读 · 0 评论 -
[LeetCode-Algorithms-53] "Maximum Subarray" (2017.10.19-WEEK7)
题目链接: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原创 2017-10-19 22:25:43 · 155 阅读 · 0 评论