随笔分类 - Leetcode
摘要:Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a lette
阅读全文
摘要:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. Example 1: Example 2: my code: can't determine the
阅读全文
摘要:Count the number of prime numbers less than a non-negative number, n. Example: Approach #1: C++. Approach #2: Java. Approach #3: Python.
阅读全文
摘要:Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] +
阅读全文
摘要:You 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
阅读全文
摘要:Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc
阅读全文
摘要:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to
阅读全文
摘要:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating
阅读全文
摘要:Given a binary tree, return the inorder traversal of its nodes' values. Example: Follow up: Recursive solution is trivial, could you do it iteratively
阅读全文
摘要: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
阅读全文
摘要:Koko loves to eat bananas. There are N piles of bananas, the i-th pile has piles[i] bananas. The guards have gone and will come back in H hours. Koko
阅读全文
摘要:Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If targetexists, t
阅读全文
摘要:Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there is no non-empty subarray with sum at least K, ret
阅读全文
摘要:Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[
阅读全文
摘要:Let f(x) be the number of zeroes at the end of x!. (Recall that x! = 1 * 2 * 3 * ... * x, and by convention, 0! = 1.) For example, f(3) = 0 because 3!
阅读全文
摘要:A sorted list A contains 1, plus some number of primes. Then, for every p < q in the list, we consider the fraction p/q. What is the K-th smallest fra
阅读全文
摘要:On an N x N grid, each square grid[i][j] represents the elevation at that point (i,j). Now rain starts to fall. At time t, the depth of the water ever
阅读全文
摘要:Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays. Example 1: Note: Approach #1: Dynamic programm
阅读全文
摘要:Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pair (A, B) is defined as the absolute difference bet
阅读全文
摘要:Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number quickly from the multiplication table? Given the
阅读全文