You are given a rectangular cake of size h x w and two arrays of integers horizontalCuts and verticalCuts where:
horizontalCuts[i] is the distance from the top of the rectangular cake to the i<sup>th</sup> horizontal cut and similarly, and
verticalCuts[j] is the distance from the left of the rectangular cake to the j<sup>th</sup> vertical cut.
Return the maximum area of a piece of cake after you cut at each horizontal and vertical position provided in the arrayshorizontalCutsandverticalCuts. Since the answer can be a large number, return this modulo10<sup>9</sup><span> </span>+ 7.
A string s is called good if there are no two different characters in s that have the same frequency.
Given a string s, return* the minimum number of characters you need to delete to make sgood.*
The frequency of a character in a string is the number of times it appears in the string. For example, in the string "aab", the frequency of 'a' is 2, while the frequency of 'b' is 1.
A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. For example, 101 and 1100 are deci-binary, while 112 and 3001 are not.
Given a string n that represents a positive decimal integer, return the minimum number of positive deci-binary numbers needed so that they sum up to n.
Solution
遍历所有字符,返回字符串中的最大整数。
Code
1 2 3 4 5 6 7 8 9
classSolution { publicintminPartitions(String n) { charmax='0'; for(char s : n.toCharArray()){ if(s > max) max = s; } return max - '0'; } }
There is a street with n * 2plots, where there are n plots on each side of the street. The plots on each side are numbered from 1 to n. On each plot, a house can be placed.
Return the number of ways houses can be placed such that no two houses are adjacent to each other on the same side of the street. Since the answer may be very large, return it modulo10<sup>9</sup><span> </span>+ 7.
Note that if a house is placed on the i<sup>th</sup> plot on one side of the street, a house can also be placed on the i<sup>th</sup> plot on the other side of the street.
You are given a 0-indexed integer array nums. In one operation, select any non-negative integer x and an index i, then updatenums[i] to be equal to nums[i] AND (nums[i] XOR x).
Note that AND is the bitwise AND operation and XOR is the bitwise XOR operation.
Return the maximum possible bitwise XOR of all elements of nums after applying the operation any number of times.
You are given an integer n. There is an undirected graph with n nodes, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [a<sub>i</sub>, b<sub>i</sub>] denotes that there exists an undirected edge connecting nodes a<sub>i</sub> and b<sub>i</sub>.
Return the number of pairs of different nodes that are unreachable from each other.
You are given an array of strings products and a string searchWord.
Design a system that suggests at most three product names from products after each character of searchWord is typed. Suggested products should have common prefix with searchWord. If there are more than three products with a common prefix return the three lexicographically minimums products.
Return a list of lists of the suggested products after each character of searchWord is typed.
You are given an array of words where each word consists of lowercase English letters.
word<sub>A</sub> is a predecessor of word<sub>B</sub> if and only if we can insert exactly one letter anywhere in word<sub>A</sub>without changing the order of the other characters to make it equal to word<sub>B</sub>.
For example, "abc" is a predecessor of "ab<u>a</u>c", while "cba" is not a predecessor of "bcad".
A word chain* *is a sequence of words [word<sub>1</sub>, word<sub>2</sub>, ..., word<sub>k</sub>] with k >= 1, where word<sub>1</sub> is a predecessor of word<sub>2</sub>, word<sub>2</sub> is a predecessor of word<sub>3</sub>, and so on. A single word is trivially a word chain with k == 1.
Return *the length of the longest possible word chain with words chosen from the given list of *words.
You are given an array of positive integers nums and want to erase a subarray containing unique elements. The score you get by erasing the subarray is equal to the sum of its elements.
Return the maximum score you can get by erasing exactly one subarray.
An array b is called to be a subarray of a if it forms a contiguous subsequence of a, that is, if it is equal to a[l],a[l+1],...,a[r] for some (l,r).
You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the i<sup>th</sup> spell and potions[j] represents the strength of the j<sup>th</sup> potion.
You are also given an integer success. A spell and potion pair is considered successful if the product of their strengths is at leastsuccess.
Return an integer array pairs of length n where pairs[i] is the number of potions that will form a successful pair with the i<sup>th</sup> spell.