
leetcode
文章平均质量分 67
农民小飞侠
如果放弃了,那还谈什么理想
展开
-
[leetcode] 858. Mirror Reflection
感想我搜了一下,好像还没有搜到中文博客关于这一题的解题报告,我这里弥补一下空缺。problemThere is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining cor...原创 2018-07-06 10:03:26 · 623 阅读 · 2 评论 -
[leetcode] 72. Edit Distance动态规划
感想这是我在牛客网上看到的很经典的一个动态规划的题目,我当时也是不怎么懂,这里我把它记录下来,尽量写详细。problemGiven two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 ...原创 2018-05-01 00:16:05 · 296 阅读 · 1 评论 -
[leetcode] 146. LRU Cache
感想这道题在leetcode是hard的难度,通过率只有21.2%,我记得在某次笔试的时候做到了这一道题,那时候做得不怎么好,我这里把记录一下我以前写的代码,就当复习一下题目Design and implement a data structure forLeast Recently Used (LRU) cache. It should support the following ...原创 2018-09-10 16:00:00 · 366 阅读 · 1 评论 -
[leetcode] 454. 4Sum II
DescriptionGiven four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D have...原创 2019-01-17 21:11:36 · 217 阅读 · 0 评论 -
[leetcode] 456. 132 Pattern
DescriptionGiven a sequence of n integers a1, a2, …, an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and a_i < a_k < a_j. Design an algorithm that takes a list of n numb...原创 2019-01-17 21:51:26 · 156 阅读 · 0 评论 -
[leetcode] 721. Accounts Merge
DescriptionGiven a list accounts, each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the a...原创 2019-01-19 21:07:05 · 451 阅读 · 0 评论 -
[leetcode] 211. Add and Search Word - Data structure design
DescriptionDesign a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing o...原创 2019-01-19 21:19:46 · 254 阅读 · 0 评论 -
[leetcode] 258. Add Digits
DescriptionGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.Example:Input: 38Output: 2 Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. ...原创 2019-01-19 21:37:36 · 190 阅读 · 0 评论 -
[leetcode] 623. Add One Row to Tree
DescriptionGiven the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth 1.The adding rule is: given a positi...原创 2019-01-19 21:51:30 · 218 阅读 · 0 评论 -
[leetcode] 306. Additive Number
DescriptionAdditive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent numb...原创 2019-01-19 23:50:04 · 169 阅读 · 0 评论 -
[leetcode] 863. All Nodes Distance K in Binary Tree
DescriptionWe are given a binary tree (with root node root), a target node, and an integer value K.Return a list of the values of all nodes that have a distance K from the target node. The answer c...原创 2019-01-20 12:01:34 · 231 阅读 · 0 评论 -
[leetcode] 816. Ambiguous Coordinates
DescriptionWe had some 2-dimensional coordinates, like “(1, 3)” or “(2, 0.5)”. Then, we removed all commas, decimal points, and spaces, and ended up with the string S. Return a list of strings repr...原创 2019-01-20 14:14:09 · 227 阅读 · 0 评论 -
[leetcode] 413. Arithmetic Slices
DescriptionA sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmeti...原创 2019-01-20 14:25:30 · 230 阅读 · 0 评论 -
[leetcode] 441. Arranging Coins
DescriptionYou have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find the total number of full staircase rows that can be fo...原创 2019-01-20 14:31:58 · 179 阅读 · 0 评论 -
[leetcode] 565. Array Nesting
DescriptionA zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], … } subjected to the rule belo...原创 2019-01-20 14:50:24 · 598 阅读 · 0 评论 -
[leetcode] 735. Asteroid Collision
DescriptionWe are given an array asteroids of integers representing asteroids in a row.For each asteroid, the absolute value represents its size, and the sign represents its direction (positive mean...原创 2019-01-20 15:02:07 · 304 阅读 · 0 评论 -
[leetcode] 844. Backspace String Compare
DescriptionGiven two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.Example 1:Input: S = "ab#c", T = "ad#c"Output: trueExplan...原创 2019-01-20 15:13:07 · 206 阅读 · 1 评论 -
[leetcode] 682. Baseball Game
DescriptionYou’re now a baseball game point recorder.Given a list of strings, each string can be one of the 4 following types:Integer (one round’s score): Directly represents the number of points ...原创 2019-01-20 15:40:27 · 173 阅读 · 0 评论 -
[leetcode] 227. Basic Calculator II
DescriptionImplement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division...原创 2019-01-20 15:48:23 · 158 阅读 · 0 评论 -
[leetcode] 224. Basic Calculator
DescriptionImplement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers a...原创 2019-01-20 15:58:49 · 264 阅读 · 0 评论 -
[leetcode] 667. Beautiful Arrangement II
DescriptionGiven two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement:Suppose this list is [a1, a2,...原创 2019-01-20 20:13:09 · 206 阅读 · 1 评论 -
[leetcode] 859. Buddy Strings
DescriptionGiven two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B.Example 1:Input: A = "ab", B = "ba"Output: trueExam...原创 2019-01-31 14:16:20 · 195 阅读 · 0 评论 -
[leetcode] 672. Bulb Switcher II
DescriptionThere is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different ...原创 2019-01-31 14:48:37 · 178 阅读 · 0 评论 -
[leetcode] 319. Bulb Switcher
DescriptionThere are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s off or ...原创 2019-01-31 14:54:27 · 237 阅读 · 0 评论 -
[leetcode] 299. Bulls and Cows
DescriptionYou are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provid...原创 2019-01-31 21:24:15 · 283 阅读 · 0 评论 -
[leetcode] 464. Can I Win
DescriptionIn the “100 game,” two players take turns adding, to a running total, any integer from 1…10. The player who first causes the running total to reach or exceed 100 wins.What if we change th...原创 2019-01-31 22:02:53 · 168 阅读 · 0 评论 -
[leetcode] 650. 2 Keys Keyboard
DescriptionInitially on a notepad only one character ‘A’ is present. You can perform two operations on this notepad for each step:Copy All: You can copy all the characters present on the notepad (p...原创 2019-01-16 21:02:48 · 184 阅读 · 0 评论 -
[leetcode] 717. 1-bit and 2-bit Characters
DescriptionWe have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11).Now given a string represented by sever...原创 2019-01-16 21:23:04 · 179 阅读 · 0 评论 -
[leetcode] 714. Best Time to Buy and Sell Stock with Transaction Fee
DescriptionYour are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer fee representing a transaction fee.You may comple...原创 2019-01-27 23:43:18 · 251 阅读 · 0 评论 -
[leetcode] 605. Can Place Flowers
DescriptionSuppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both woul...原创 2019-02-01 18:43:31 · 208 阅读 · 0 评论 -
[leetcode] 135. Candy
DescriptionThere are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at l...原创 2019-02-01 19:39:59 · 250 阅读 · 0 评论 -
[leetcode] 853. Car Fleet
DescriptionN cars are going to the same destination along a one lane road. The destination is target miles away.Each car i has a constant speed speed[i] (in miles per hour), and initial position po...原创 2019-02-01 20:33:36 · 243 阅读 · 0 评论 -
[leetcode] 787. Cheapest Flights Within K Stops
DescriptionThere are n cities connected by m flights. Each fight starts from city u and arrives at v with a price w.Now given all the cities and flights, together with starting city src and the dest...原创 2019-02-01 21:11:05 · 374 阅读 · 0 评论 -
[leetcode] 693. Binary Number with Alternating Bits
DescriptionGiven a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.Example 1:Input: 5Output: TrueExplanation:The binary re...原创 2019-01-28 12:50:08 · 215 阅读 · 0 评论 -
[leetcode] 107. Binary Tree Level Order Traversal II
DescriptionGiven a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,nul...原创 2019-01-28 15:19:19 · 197 阅读 · 0 评论 -
[leetcode] 322. Coin Change 零钱兑换-动态规划
DescriptionYou 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 amou...原创 2019-02-02 17:44:19 · 234 阅读 · 1 评论 -
[leetcode] 377. Combination Sum IV
DescriptionGiven an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4...原创 2019-02-02 21:59:25 · 927 阅读 · 0 评论 -
[leetcode] 537. Complex Number Multiplication
DescriptionGiven two strings representing two complex numbers.You need to return a string representing their multiplication. Note i2 = -1 according to the definition.Example 1:Input: "1+1i", "1+1i...原创 2019-02-03 10:19:30 · 198 阅读 · 0 评论 -
[leetcode] 829. Consecutive Numbers Sum
DescriptionGiven a positive integer N, how many ways can we write it as a sum of consecutive positive integers?Example 1:Input: 5Output: 2Explanation: 5 = 5 = 2 + 3Example 2:Input: 9Output: 3...原创 2019-02-03 10:30:11 · 223 阅读 · 0 评论 -
[leetcode] 309. Best Time to Buy and Sell Stock with Cooldown
DescriptionSay 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 as many transactions as you like (i...原创 2019-01-23 11:24:49 · 435 阅读 · 0 评论