LeetCode 88.27 88. Combine two ordered arrays 27. Remove elements

88. Combine two ordered arrays

Insert picture description here
Idea:
Put array 2 into array 1 first, and then sort.

Insert picture description here
Insert picture description here
Looking at the problem-solving problem, I found that directly using slices is easy to read. The time complexity and space complexity are the same because slicing and then assigning uses an operation similar to a for loop.
Insert picture description here
Insert picture description here
Long knowledge.

27. Remove elements

Insert picture description here
Ideas
Traverse the array equal to val to delete. But using del will automatically move the array forward after deletion, and let the subscript continue to be equal to now after deletion. Finally, the length of the array is returned.
Of course, it is inefficient. Although it can be achieved, it is very silly! ! !
Insert picture description here
Insert picture description here

It is found that the reverse order is used to save the operation of leaving the subscript unchanged after deletion.
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_43710889/article/details/108538807