随笔分类 - LeetCode
摘要:In a deck of cards, every card has a unique integer. You can order the deck in any order you want. Initially, all the cards start face down (unreveale
阅读全文
摘要:For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees. A binary tree X is flip e
阅读全文
摘要:Given an array of 4 digits, return the largest 24 hour time that can be made. The smallest 24 hour time is 00:00, and the largest is 23:59. Starting f
阅读全文
摘要:Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result of a sequence of push and pop o
阅读全文
摘要:Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1. Return the least number of moves to make every value in
阅读全文
摘要:A chess knight can move as indicated in the chess diagram below: . This time, we place our chess knight on any numbered key of a phone pad (indicated
阅读全文
摘要:Write a class RecentCounter to count recent requests. It has only one method: ping(int t), where t represents some time in milliseconds. Return the nu
阅读全文
摘要:Given a square array of integers A, we want the minimum sum of a falling path through A. A falling path starts at any element in the first row, and ch
阅读全文
摘要:In an array A of 0s and 1s, how many non-empty subarrays have sum S? Example 1: Note: 通用解法就是求连续数组的和有多少个,这种题代码都不会变的 把和存起来,给后面的数字-S看有没有这个和,有的话加起来,然后a[an
阅读全文
摘要:Every email consists of a local name and a domain name, separated by the @ sign. For example, in alice@leetcode.com, alice is the local name, and leet
阅读全文
摘要:Given an array A, we may rotate it by a non-negative integer K so that the array becomes A[K], A[K+1], A{K+2], ... A[A.length - 1], A[0], A[1], ..., A
阅读全文
摘要:We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row. Each glass holds one cup
阅读全文
摘要:Given a directed, acyclic graph of N nodes. Find all possible paths from node 0 to node N-1, and return them in any order. The graph is given as follo
阅读全文
摘要:We are given two strings, A and B. A shift on A consists of taking string A and moving the leftmost character to the rightmost position. For example,
阅读全文
摘要:We are given an array A of positive integers, and two positive integers L and R (L <= R). Return the number of (contiguous, non-empty) subarrays such
阅读全文
摘要:Given string S and a dictionary of words words, find the number of words[i] that is a subsequence of S. Note: All words in words and S will only consi
阅读全文
摘要:A Tic-Tac-Toe board is given as a string array board. Return True if and only if it is possible to reach this board position during the course of a va
阅读全文
摘要:We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may be rotated. Given N, how many ways are there to tile a 2 x
阅读全文
摘要:S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sorted in some custom order previously. We want to per
阅读全文
摘要:You are playing a simplified Pacman game. You start at the point (0, 0), and your destination is(target[0], target[1]). There are several ghosts on th
阅读全文