亚麻上网做题,遇见了水果顺序的题目,就是给你个array of array[[苹果,苹果],[橘子,香蕉,anything,苹果]],再给你个array[香蕉,苹果,苹果,香蕉,橘子,香蕉,香蕉,苹果]问世后面那array是不是前面那array of array 顺序的排了,在这个例子里面是算顺序排的,各个子array之间可以插入不同的值,但子array的顺序得对,子array内部的顺序也得对。
array: [香蕉,苹果,苹果,香蕉,橘子,香蕉,香蕉,苹果]
---> 忽略 【match 1】忽略 【 match 2 】
第二个是给你个array of int,叫你给整成个bst, 然后再问你bst里面其中两个值之间的距离是多少。
另外看到别人的这题也报一下:
Given a list of unique integers nums , construct a BST from it (you need to insert nodes one-by-one with the given order to get the BST) and find the distance between two nodes node1 and node2 . Distance is the number of edges between two nodes. If any of the given nodes does not appear in the BST, return -1 .
You are given an array of A of N elements. You have performed Q queries in it. In each query, you can select an index I ( 0 - based) and perform the following operation:
for j = I + 1 to N
if A[j] < A[i]
A[j] = 0
You are required to print the version of array A after all queries Q .
Examples:
Input:
1 (no of test cases)
5 2 (N & Q)
4 3 4 3 2 (the queries)
Output:
4 3 4 0 0
Explanation:
After the first query: {4, 3, 4, 3, 0}
After the second query: {4, 3, 4, 0, 0}
还有 Mergers
You are given two strings A and B. You need to merge these strings, considering all characters that are both prefix of A and suffix of B once.
For example: A = “abcde”, B = “cdefg”, merged string = “abcdefg”.
Before merging, any one of the following operations can be performed at max once:
reverse A
reverse B
add 1 char at the end of A
add 1 char at the beginning of B
Print the minimum length possible for the merged string.
Constraints:
1 <= T <= 1000 (no of test cases)
1 <= |A|, |B| <= 10^4
Examples:
2 (no of test cases)
ababc
bcabc
cdefg
abhgf