Fork me on GitHub
摘要:终于将LeetCode的大部分题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 对应的 Github 项目的同步地址如下,欢迎大家关注点赞❤️ https://github.com/grandyang/leetcode 如果各位看 阅读全文
posted @ 2015-06-28 23:20 Grandyang 阅读 (679111) 评论 (148) 编辑
摘要:In a 2D grid of s and s, we change at most one to a . After, what is the size of the largest island? (An island is a 4 directionally connected group o 阅读全文
posted @ 2019-10-13 23:32 Grandyang 阅读 (30) 评论 (0) 编辑
摘要:We are given two arrays and of words. Each word is a string of lowercase letters. Now, say that word is a subset of word if every letter in occurs in 阅读全文
posted @ 2019-10-04 23:33 Grandyang 阅读 (88) 评论 (0) 编辑
摘要:A character is unique in string if it occurs exactly once in it. For example, in string , the only unique characters are and . Let's define as the num 阅读全文
posted @ 2019-10-01 23:36 Grandyang 阅读 (69) 评论 (0) 编辑
摘要:Given an array , partition it into two (contiguous) subarrays and so that: Every element in is less than or equal to every element in . and are non em 阅读全文
posted @ 2019-09-29 23:25 Grandyang 阅读 (53) 评论 (0) 编辑
摘要:Given a positive integer , how many ways can we write it as a sum of consecutive positive integers? Example 1: Example 2: Example 3: Note: `1 这道题给了一个正 阅读全文
posted @ 2019-09-26 23:54 Grandyang 阅读 (96) 评论 (2) 编辑
摘要:In a deck of cards, each card has an integer written on it. Return if and only if you can choose such that it is possible to split the entire deck int 阅读全文
posted @ 2019-09-23 23:20 Grandyang 阅读 (90) 评论 (0) 编辑
摘要:An undirected, connected tree with nodes labelled and `edges` are given. The th edge connects nodes and together. Return a list , where is the sum of 阅读全文
posted @ 2019-09-14 23:46 Grandyang 阅读 (213) 评论 (0) 编辑
摘要:A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns. The graph is given as follows: is a list of all nodes such 阅读全文
posted @ 2019-09-12 23:55 Grandyang 阅读 (215) 评论 (4) 编辑
摘要:Two strings and are similar if we can swap two letters (in different positions) of , so that it equals . For example, and are similar (swapping at pos 阅读全文
posted @ 2019-09-10 22:14 Grandyang 阅读 (137) 评论 (0) 编辑
摘要:Given an array of integers , sort the array in ascending order. Example 1: Example 2: Note: 1. `1 这道题让我们给数组排序,在平时刷其他题的时候,遇到要排序的时候,一般都会调用系统自带的排序函数,像 C+ 阅读全文
posted @ 2019-09-07 23:52 Grandyang 阅读 (177) 评论 (0) 编辑
摘要:This problem is an interactive problem new to the LeetCode platform. We are given a word list of unique words, each word is 6 letters long, and one wo 阅读全文
posted @ 2019-09-02 21:45 Grandyang 阅读 (321) 评论 (0) 编辑
摘要:In an election, the th vote was cast for at time . Now, we would like to implement the following query function: will return the number of the person 阅读全文
posted @ 2019-08-27 23:48 Grandyang 阅读 (166) 评论 (0) 编辑
摘要:An undirected, connected graph of N nodes (labeled ) is given as . , and is in the list exactly once, if and only if nodes and are connected. Return t 阅读全文
posted @ 2019-08-25 23:37 Grandyang 阅读 (250) 评论 (0) 编辑
摘要:Given a rooted binary tree, return the lowest common ancestor of its deepest leaves. Recall that: The node of a binary tree is a leaf if and only if i 阅读全文
posted @ 2019-08-22 22:39 Grandyang 阅读 (285) 评论 (0) 编辑
摘要:We are given a list of (axis aligned) . Each , where (x1, y1) are the coordinates of the bottom left corner, and (x2, y2) are the coordinates of the t 阅读全文
posted @ 2019-08-18 02:56 Grandyang 阅读 (342) 评论 (0) 编辑
摘要:Given an array of integers, for each integer we need to choose either or , and add to . After this process, we have some array . Return the smallest p 阅读全文
posted @ 2019-08-15 23:29 Grandyang 阅读 (169) 评论 (0) 编辑
摘要:Strings and are similar (for some non negative integer ) if we can swap the positions of two letters in exactly times so that the resulting string equ 阅读全文
posted @ 2019-08-13 02:37 Grandyang 阅读 (340) 评论 (0) 编辑
摘要:On an N x N , the numbers from to are written boustrophedonically starting from the bottom left of the board, and alternating direction each row. For 阅读全文
posted @ 2019-08-12 21:16 Grandyang 阅读 (244) 评论 (0) 编辑
摘要:There are workers. The th worker has a and a minimum wage expectation . Now we want to hire exactly workers to form a paid group . When hiring a group 阅读全文
posted @ 2019-08-09 20:34 Grandyang 阅读 (354) 评论 (0) 编辑
摘要:Given an array of integers, for each integer we may choose any with ` K 这道题说是给了一个非负数的数组,和一个非负数K,说是数组中的每一个数字都可以加上 [ K, K] 范围内的任意一个数字,问新数组的最大值最小值之间的差值最小 阅读全文
posted @ 2019-08-07 22:20 Grandyang 阅读 (238) 评论 (0) 编辑
摘要:Return the length of the shortest, non empty, contiguous subarray of with sum at least . If there is no non empty subarray with sum at least , return 阅读全文
posted @ 2019-08-04 22:01 Grandyang 阅读 (301) 评论 (0) 编辑
摘要:Given an array of integers , find the sum of , where ranges over every (contiguous) subarray of . Since the answer may be large, return the answer mod 阅读全文
posted @ 2019-07-30 22:53 Grandyang 阅读 (297) 评论 (0) 编辑
摘要:We are given a 2 dimensional . is an empty cell, is a wall, is the starting point, ( , , ...) are keys, and ( , , ...) are locks. We start at the star 阅读全文
posted @ 2019-07-20 23:27 Grandyang 阅读 (269) 评论 (1) 编辑
摘要:Let's say a positive integer is a superpalindrome if it is a palindrome, and it is also the square of a palindrome. Now, given two positive integers a 阅读全文
posted @ 2019-07-17 23:49 Grandyang 阅读 (254) 评论 (0) 编辑
摘要:A car travels from a starting position to a destination which is miles east of the starting position. Along the way, there are gas stations. Each repr 阅读全文
posted @ 2019-07-14 23:58 Grandyang 阅读 (274) 评论 (0) 编辑
摘要:Given an array of non negative integers, return an array consisting of all the even elements of , followed by all the odd elements of . You may return 阅读全文
posted @ 2019-07-11 23:32 Grandyang 阅读 (2484) 评论 (0) 编辑
摘要:We run a preorder depth first search on the of a binary tree. At each node in this traversal, we output dashes (where is the depth of this node), then 阅读全文
posted @ 2019-07-08 08:22 Grandyang 阅读 (364) 评论 (0) 编辑
摘要:A positive integer is magical if it is divisible by either A or B. Return the N th magical number. Since the answer may be very large, return it modul 阅读全文
posted @ 2019-07-07 23:49 Grandyang 阅读 (328) 评论 (0) 编辑
摘要:In a row of trees, the th tree produces fruit with type . You start at any tree of your choice, then repeatedly perform the following steps: 1. Add on 阅读全文
posted @ 2019-07-03 23:45 Grandyang 阅读 (1300) 评论 (0) 编辑
摘要:There are G people in a gang, and a list of various crimes they could commit. The th crime generates a and requires gang members to participate. If a 阅读全文
posted @ 2019-06-29 22:52 Grandyang 阅读 (343) 评论 (0) 编辑
摘要:We are given , a length string of characters from the set . (These letters stand for "decreasing" and "increasing".) A valid permutation is a permutat 阅读全文
posted @ 2019-06-26 23:22 Grandyang 阅读 (1965) 评论 (1) 编辑
摘要:Starting with an undirected graph (the "original graph") with nodes from to , subdivisions are made to some of the edges. The graph is given as follow 阅读全文
posted @ 2019-06-23 23:49 Grandyang 阅读 (278) 评论 (0) 编辑
摘要:We have a sorted set of digits , a non empty subset of . (Note that is not included.) Now, we write numbers using these digits, using each digit as ma 阅读全文
posted @ 2019-06-20 23:53 Grandyang 阅读 (407) 评论 (0) 编辑
摘要:You are given eggs, and you have access to a building with floors from to . Each egg is identical in function, and if an egg breaks, you cannot drop i 阅读全文
posted @ 2019-06-18 22:09 Grandyang 阅读 (754) 评论 (1) 编辑
摘要:Write a class which collects daily price quotes for some stock, and returns the span of that stock's price for the current day. The span of the stock' 阅读全文
posted @ 2019-06-15 23:27 Grandyang 阅读 (529) 评论 (0) 编辑
摘要:Given an array of integers , consider all non empty subsequences of . For any sequence S, let the width of S be the difference between the maximum and 阅读全文
posted @ 2019-06-13 23:02 Grandyang 阅读 (337) 评论 (0) 编辑
摘要:Write an iterator that iterates through a run length encoded sequence. The iterator is initialized by , where is a run length encoding of some sequenc 阅读全文
posted @ 2019-06-11 22:47 Grandyang 阅读 (478) 评论 (0) 编辑
摘要:A string of lowercase letters is given. Then, we may make any number of moves . In each move, we choose one of the first letters (starting from the le 阅读全文
posted @ 2019-06-09 23:40 Grandyang 阅读 (552) 评论 (0) 编辑
摘要:Implement , a class which simulates the operation of a stack like data structure. has two functions: , which pushes an integer onto the stack. , which 阅读全文
posted @ 2019-06-07 22:34 Grandyang 阅读 (535) 评论 (0) 编辑
摘要:We have an array of non negative integers. For every (contiguous) subarray (with `i 这是一道蛮有意思的题目,说是给了我们一个数组,里面都是非负数,问我们所有连续的子数组'或'起来能产生多少个不同的值。虽说这只是一道 阅读全文
posted @ 2019-06-05 23:15 Grandyang 阅读 (503) 评论 (0) 编辑