Fork me on GitHub
摘要:终于将LeetCode的大部分题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 博主还制作了一款 网页版APP,方便大家进行查阅,网址如下: https://grandyang.com 对应的 Github 项目 的同步地址如下, 阅读全文
posted @ 2015-06-28 23:20 Grandyang 阅读(1094507) 评论(155) 推荐(111) 编辑
摘要:Given a string s, we make queries on substrings of s. For each query queries[i] = [left, right, k], we may rearrange the substring s[left], ..., s[rig 阅读全文
posted @ 2021-08-02 10:23 Grandyang 阅读(12) 评论(0) 推荐(0) 编辑
摘要:Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.) (Recall that an integer is prime if and only if it 阅读全文
posted @ 2021-07-31 21:36 Grandyang 阅读(15) 评论(0) 推荐(0) 编辑
摘要:You have an infinite number of stacks arranged in a row and numbered (left to right) from 0, each of the stacks has the same maximum capacity. Impleme 阅读全文
posted @ 2021-07-29 22:43 Grandyang 阅读(15) 评论(0) 推荐(0) 编辑
摘要:Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences. After doing so, 阅读全文
posted @ 2021-07-27 21:55 Grandyang 阅读(25) 评论(0) 推荐(0) 编辑
摘要:Let the function f(s) be the frequency of the lexicographically smallest character in a non-empty string s. For example, if s = "dcce" then f(s) = 2 b 阅读全文
posted @ 2021-07-26 03:03 Grandyang 阅读(22) 评论(0) 推荐(0) 编辑
摘要:A transaction is possibly invalid if: the amount exceeds $1000, or; if it occurs within (and including) 60 minutes of another transaction with the sam 阅读全文
posted @ 2021-07-22 22:58 Grandyang 阅读(29) 评论(0) 推荐(0) 编辑
摘要:Given a string s, return the last substring of s in lexicographical order. Example 1: Input: s = "abab" Output: "bab" Explanation: The substrings are 阅读全文
posted @ 2021-07-21 23:01 Grandyang 阅读(17) 评论(0) 推荐(0) 编辑
摘要:Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the ne 阅读全文
posted @ 2021-07-20 22:27 Grandyang 阅读(19) 评论(0) 推荐(0) 编辑
摘要:Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum 阅读全文
posted @ 2021-07-17 09:43 Grandyang 阅读(28) 评论(0) 推荐(0) 编辑
摘要:You are given an array of strings words and a string chars. A string is good if it can be formed by characters from chars (each character can only be 阅读全文
posted @ 2021-07-15 09:27 Grandyang 阅读(14) 评论(0) 推荐(0) 编辑
摘要:Design a data structure that efficiently finds the majority element of a given subarray. The majority element of a subarray is an element that occurs  阅读全文
posted @ 2021-07-14 13:21 Grandyang 阅读(23) 评论(0) 推荐(0) 编辑
摘要:Given a string text, we are allowed to swap two of the characters in the string. Find the length of the longest substring with repeated characters. Ex 阅读全文
posted @ 2021-07-09 23:25 Grandyang 阅读(82) 评论(0) 推荐(0) 编辑
摘要:You have d dice and each die has f faces numbered 1, 2, ..., f. Return the number of possible ways (out of fd total ways) modulo 109 + 7 to roll the d 阅读全文
posted @ 2021-07-08 13:08 Grandyang 阅读(39) 评论(0) 推荐(0) 编辑
摘要:Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year. Example 1: Input: date = "2019- 阅读全文
posted @ 2021-07-05 03:54 Grandyang 阅读(41) 评论(0) 推荐(0) 编辑
摘要:You are given a string text. You should split it to k substrings (subtext1, subtext2, ..., subtextk) such that: subtexti is a non-empty string. The co 阅读全文
posted @ 2021-07-04 05:01 Grandyang 阅读(157) 评论(0) 推荐(0) 编辑
摘要:Implement a SnapshotArray that supports the following interface: SnapshotArray(int length) initializes an array-like data structure with the given len 阅读全文
posted @ 2021-06-26 14:14 Grandyang 阅读(106) 评论(0) 推荐(0) 编辑
摘要:Two players play a turn based game on a binary tree. We are given the root of this binary tree, and the number of nodes n in the tree. n is odd, and e 阅读全文
posted @ 2021-06-21 13:30 Grandyang 阅读(108) 评论(0) 推荐(0) 编辑
摘要:Given an array nums of integers, a move consists of choosing any element and decreasing it by 1. An array A is a zigzag array if either: Every even-in 阅读全文
posted @ 2021-06-21 04:07 Grandyang 阅读(48) 评论(0) 推荐(0) 编辑
摘要:Alice and Bob continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of 阅读全文
posted @ 2021-06-18 12:57 Grandyang 阅读(98) 评论(0) 推荐(0) 编辑
摘要:Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn' 阅读全文
posted @ 2021-06-13 15:47 Grandyang 阅读(73) 评论(0) 推荐(0) 编辑
摘要:On an alphabet board, we start at position (0, 0), corresponding to character board[0][0]. Here, board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", 阅读全文
posted @ 2021-06-11 13:57 Grandyang 阅读(65) 评论(0) 推荐(0) 编辑
摘要:The Tribonacci sequence Tn is defined as follows: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0. Given n, return the value of Tn. Exa 阅读全文
posted @ 2021-06-08 21:59 Grandyang 阅读(90) 评论(0) 推荐(0) 编辑
摘要:Given two arrays of integers with equal lengths, return the maximum value of: |arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j| where the maximum is 阅读全文
posted @ 2021-06-07 05:45 Grandyang 阅读(77) 评论(0) 推荐(0) 编辑
摘要:Given an array arr of positive integers, consider all binary trees such that: Each node has either 0 or 2 children; The values of arr correspond to th 阅读全文
posted @ 2021-05-30 07:45 Grandyang 阅读(95) 评论(2) 推荐(0) 编辑
摘要:Consider a directed graph, with nodes labelled 0, 1, ..., n-1. In this graph, each edge is either red or blue, and there could be self-edges or parall 阅读全文
posted @ 2021-05-27 11:56 Grandyang 阅读(103) 评论(0) 推荐(0) 编辑
摘要:Given a list of dominoes, dominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a==c and b==d), or (a==d and b==c) - that 阅读全文
posted @ 2021-05-24 02:24 Grandyang 阅读(76) 评论(0) 推荐(0) 编辑
摘要:In a project, you have a list of required skills req_skills, and a list of people. The ith person people[i] contains a list of skills that the person 阅读全文
posted @ 2021-05-19 11:37 Grandyang 阅读(122) 评论(0) 推荐(0) 编辑
摘要:We are given hours, a list of the number of hours worked per day for a given employee. A day is considered to be a tiring day if and only if the numbe 阅读全文
posted @ 2021-05-16 01:22 Grandyang 阅读(99) 评论(0) 推荐(0) 编辑
摘要:Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1. Sort the elements of arr1 such that the 阅读全文
posted @ 2021-05-13 12:32 Grandyang 阅读(90) 评论(0) 推荐(0) 编辑
摘要:博主在用 Hexo 搭建博客的时候,一直在考虑评论系统用什么,最终比较了多家,决定用 Gitalk,这是一个基于 Github Issues 的评论系统,所有的评论内容都保存在 Github Issues 中,每篇博客对应一个 Issues。只有登陆 Github 账号才能评论,大多数人应该都会有 阅读全文
posted @ 2021-05-12 12:13 Grandyang 阅读(126) 评论(0) 推荐(0) 编辑
摘要:A string is a valid parentheses string (denoted VPS) if and only if it consists of "(" and ")" characters only, and: It is the empty string, or It can 阅读全文
posted @ 2021-05-09 22:38 Grandyang 阅读(103) 评论(0) 推荐(0) 编辑
摘要:Given the root of a binary tree, each node in the tree has a distinct value. After deleting all nodes with a value in to_delete, we are left with a fo 阅读全文
posted @ 2021-05-09 02:33 Grandyang 阅读(673) 评论(0) 推荐(0) 编辑
摘要:There are n flights that are labeled from 1 to n. You are given an array of flight bookings bookings, where bookings[i] = [firsti, lasti, seatsi] repr 阅读全文
posted @ 2021-05-06 12:25 Grandyang 阅读(210) 评论(0) 推荐(0) 编辑
摘要:Given a valid (IPv4) IP address, return a defanged version of that IP address. A defanged IP address replaces every period "." with "[.]". Example 1: 阅读全文
posted @ 2021-05-05 12:48 Grandyang 阅读(207) 评论(0) 推荐(0) 编辑
摘要:Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evalua 阅读全文
posted @ 2021-05-02 06:41 Grandyang 阅读(173) 评论(0) 推荐(0) 编辑
摘要:When you run hexo g, you might get the following error: call_and_retry_last allocation failed - javascript heap out of memory Solution: Try to run exp 阅读全文
posted @ 2021-04-26 02:50 Grandyang 阅读(52) 评论(0) 推荐(0) 编辑
摘要:We have a sequence of books: the i-th book has thickness books[i][0] and height books[i][1]. We want to place these books in order onto bookcase shelv 阅读全文
posted @ 2021-04-22 15:56 Grandyang 阅读(156) 评论(0) 推荐(0) 编辑
摘要:When use nginx to configure https with ssl 443 port, it might be timed out, but your http 80 port work correctly. At this time, if you nginx configure 阅读全文
posted @ 2021-04-20 16:15 Grandyang 阅读(41) 评论(0) 推荐(0) 编辑
摘要:In an infinite binary tree where every node has two children, the nodes are labelled in row order. In the odd numbered rows (ie., the first, third, fi 阅读全文
posted @ 2021-04-15 15:55 Grandyang 阅读(151) 评论(0) 推荐(0) 编辑
摘要:Once you deployed the hexo with Nginx on your web instance, you might get the 403 forbidden error, try the following step to fix: Solution: Run vim /e 阅读全文
posted @ 2021-04-11 17:18 Grandyang 阅读(64) 评论(0) 推荐(0) 编辑
Fork me on GitHub