1 | Input: num1 = "2", num2 = "3" |
1 | class Solution { |
1 | Input: num1 = "2", num2 = "3" |
1 | class Solution { |
1 | Example 1: |
1 | class Solution { |
Given a list of strings words representing an English Dictionary, find the longest word in words that can be built one character at a time by other words in words. If there is more than one possible answer, return the longest word with the smallest lexicographical order.
If there is no answer, return the empty string.
Example 1:
Input:
words = [“w”,”wo”,”wor”,”worl”, “world”]
Output: “world”
Explanation:
The word “world” can be built one character at a time by “w”, “wo”, “wor”, and “worl”.
1 | class Solution { |
1 | class Solution { |
1 | Input: dict = ["cat", "bat", "rat"] |
1 | class Solution { |
1 | class Solution { |
1 | class Solution { |
1 | class Solution { |
1 | class Solution { |
1 | class MyQueue { |
1 | class MyStack { |
Design a data structure that supports the following two operations:
search(word) can search a literal word or a regular expression string containing only letters a-z or .. A . means it can represent any one letter.
Example:
1 | addWord("bad") |
Note:
字典树
1 | class TrieNode{ |
There are 2N people a company is planning to interview. The cost of flying the i-th person to city A is costs[i][0], and the cost of flying the i-th person to city B is costs[i][1].
Return the minimum cost to fly every person to a city such that exactly N people arrive in each city.
1 | Example 1: |
1 | class Solution { |
An undirected, connected tree with N nodes labelled 0…N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:1
2
3
4
5
6
7
8
9
10
11Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: [8,12,6,10,10,10]
Explanation:
Here is a diagram of the given tree:
0
/ \
1 2
/|\
3 4 5
We can see that dist(0,1) + dist(0,2) + dist(0,3) + dist(0,4) + dist(0,5)
equals 1 + 1 + 2 + 2 + 2 = 8. Hence, answer[0] = 8, and so on.
1 | class Solution { |
Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a sorted array of only the integers that appeared in all three arrays.
1 | class Solution { |
Given two binary search trees, return True if and only if there is a node in the first tree and a node in the second tree whose values sum up to a given integer target.
1 | /** |
A Stepping Number is an integer such that all of its adjacent digits have an absolute difference of exactly 1. For example, 321 is a Stepping Number while 421 is not.
Given two integers low and high, find and return a sorted list of all the Stepping Numbers in the range [low, high] inclusive.
Constraints:
0 <= low <= high <= 2 * 10^9
1 | class Solution { |
Given a string s and an integer k, find out if the given string is a K-Palindrome or not.
A string is K-Palindrome if it can be transformed into a palindrome by removing at most k characters from it.
Constraints:
1 <= s.length <= 1000
s has only lowercase English letters.
1 <= k <= s.length
1 | class Solution { |
There are some chips, and the i-th chip is at position chips[i].
You can perform any of the two following types of moves any number of times (possibly zero) on any chip:
There can be two or more chips at the same position initially.
Return the minimum cost needed to move all the chips to the same position (any position).
1 | class Solution { |
Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference.
1 | class Solution { |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
1 | class Solution { |
Given an integer n, your task is to count how many strings of length n can be formed under the following rules:
Since the answer may be too large, return it modulo 10^9 + 7.
1 | class Solution { |