leetcode from 20/04/2021

tencent

Arrays and Strings

1. Sum of two numbers

Given an integer array nums and an integer target value target, find the two integers in the array and the target values and return their array subscripts. You can assume that there is only one answer for each type of input. However, the same element in the array cannot be repeated in the answer. You can return the answers in any order.

Brute force cracking. Hashmap has to be looked at

2. Find the median of two positive ordinal groups

Given two positive-ordered (from small to large) arrays of size m and n, nums1 and nums2. Please find and return the median of the two positive ordinal groups.

Insert (nums1.end(),nums2.begin(), nums2.end()

3. The longest substring

The use of substr is forgotten. The first digit is the beginning, and the second digit is the next character

Recursively, and take care of the boundary cases. Make a matrix to determine the length of the palindrome string. False: palindrome if both ends are equal and there is only one element or none; Otherwise, it depends on whether the middle string is a palindrome string. Finally returns the starting position and the palindrome string length

4. String conversion to integer (AToi)

  • Ignore leading whitespace
  • Determine the sign
  • Check whether the input is valid and whether there is overflow risk

5. Longest public prefix

The first idea is to compare vertically (column by column). The outer loop moves the first string horizontally, and the inner loop moves by row to a different string. Break out of the loop if the characters are not equal or not long enough.

6. Sum of three numbers

Given an array nums containing n integers, determine if there are three elements a, B, and c in nums such that a + b + c = 0. Please find all the triples that sum to 0 and are not repeated. Note: Repeated triples cannot be included in the answer.

Personally, the difficulty lies in how to reduce the complexity and ensure that the triplet is not duplicated. Get the idea of double Pointers. You can sort first, but note that you should skip if you encounter the same element.

7. The sum of the nearest three

Given an array of n integers nums and a target value target. Identify the three integers in NUMs so that their sum is closest to target. Returns the sum of these three numbers. Assume that there is only one answer for each set of inputs.

And the idea of the last problem is very similar, but I consider all the special cases are useless, can go to the program to solve. Note that the innermost loop is the one that scans to the last number, and that the final sum may be smaller or larger than target.

8. Valid parentheses

This idea is relatively simple, when encountering an open parenthesis, the corresponding close parenthesis is pushed; Pop when you encounter a close parenthesis to see if it’s not equal, and finally see if the stack is empty.

Delete duplicates from sorted array

Already sorted, encounter duplicate elements can be skipped and record the number, at the same time the following value to the preceding.

The container that holds the most water

The unadorned brute-force hack is running out of time. The double pointer is on line, moving in a direction that can’t get worse, moving the one with the lower height each time.

24 PM record above 3 PM, 20 PM temporary home a little upset rhythm. This time, I don’t think I can brush the questions. My current thoughts are: many questions are not difficult, but it is annoying to realize the complexity problems and critical conditions. Problems to see more, will know more methods to solve the problem. For example, the current double pointer I get! Then STL method good ha ha! ~

——– 26/04 10am ——–

String multiplication

Note the total number of digits multiplied, low % high /, to find the position relationship.

12. Reverse the string

And they want to change it in place, just switch sides.

13. Reverse a string in a string

And the last question is not connected, according to the space to find the word, each word reversed good. Update the “head and tail” position each time.

14. Product of arrays other than itself

So this is going to require both time and space complexity, and space complexity is going to be solved by opening up another array, and then multiplying the product of the left by the product of the right

15. There are repeating elements

Erase (unique(nums.begin(), nums.end()), nums.end()));

16. Spiral matrix

Click the circle, ➡️⬇️⬅️⬆️

Spiral matrix 2

Just like we did in the previous problem, we just go to the corresponding position and assign

Merge two ordered arrays

Erase 0 after nums1, insert nums2 after nums1, sort

——– 26/04 11am ——–

2, linked list assault

——– 05/05 12:30am ——–

Hey, I haven’t studied much since the day I got back to school, and I did a little brushing yesterday. Today start of summer, first say happy start of summer. And then there’s linked list 5555

1. Reverse linked lists

The previous node becomes the next node, and the previous information about the next node is stored first, and then the current node becomes the next node, and then the current node moves back. Prev pointer is null. Apply for a curr pointer.

2. Add two numbers

You are given two non-empty linked lists representing two non-negative integers. Each digit is stored in reverse order, and only one digit can be stored per node. You add the two numbers and return a linked list representing the sum in the same form. You can assume that neither of these numbers will start with 0, except for the number 0.

You can add 0 to the one that’s short, and the value of each bit is %, and the carry is /, depending on whether there’s a carry at the end.

Merge two ordered lists

You can do it recursively, each time leaving a smaller number and recursing

4. Merge k sorted linked lists

To be honest, this problem is not too will, should be able to use the idea of the previous problem. Pairwise sequential merging.

5. Rotate the list

The tail of the list is connected to the end of the loop, and the rotate value is used to find the new head. = nullptr times out. , tail->next

6. Circular lists

Hash table (); hash table (); hash table (); hash table (); hash table (); Fast people walk twice, slow people walk once if there is a ring turtle always catch

Circular linked list 2

To find the entry point, it’s a little bit simpler to hash. I don’t understand the speed of this problem

8. Intersect linked lists

“The right people will always meet.” A + B = B + A, after I finish my road to see yours

Delete a node from the linked list

So I’m going to assign, and then I’m going to assign next->next

But in general, if YOU’re doing a lot of things, you’re going to feel a little bit better, so don’t skip the variables, and try to draw a little bit of logic on a piece of paper, so that’s fine.

——– 05/05 1:15pm ——–