Technology Sharing

150 classic interview questions

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Link:150 classic interview questions - Study plan - LeetCode, the technology growth platform loved by geeks worldwide

1. Merge two sorted arrays

Ideas:

The two pointers point to the end of the two arrays respectively, traverse forward to compare the sizes, and fill the larger ones into nums1 in reverse order.

Code:

  1. class Solution {
  2. public void merge(int[] nums1, int m, int[] nums2, int n) {
  3. int l=nums1.length-1;
  4. int i=m-1,j=n-1;
  5. while(i>=0&&j>=0){
  6. if(nums1[i]>nums2[j]){
  7. nums1[l--]=nums1[i];
  8. i--;
  9. }else{
  10. nums1[l--]=nums2[j];
  11. j--;
  12. }
  13. }
  14. while(i>=0){
  15. nums1[l--]=nums1[i--];
  16. }
  17. while(j>=0){
  18. nums1[l--]=nums2[j--];
  19. }
  20. }
  21. }

2. Remove elements

Ideas:

Code:

3. Remove duplicates from a sorted array

Ideas:

Code:

4. Remove duplicates from a sorted array II

Ideas:

Code:

5. Majority Elements

Ideas:

Code:

6. Rotate Array

Ideas:

Code:

7. The best time to buy and sell stocks

Ideas:

Code:

8. The best time to buy and sell stocks II

Ideas:

Code:

9. Jumping game

Ideas:

Code:

10. Jump Game II

Ideas:

Code:

11. H-index

Ideas:

Code:

12. O(1) time to insert, delete, and retrieve random elements

Ideas:

Code:

13. Product of an array other than itself

Ideas:

Code:

14. Gas Station

Ideas:

Code:

15. Hand out candy

Ideas:

Code:

16. Collect rainwater

Ideas:

Code:

17. Convert Roman numerals to integers

Ideas:

Code:

18. Convert integers to Roman numerals

Ideas:

Code:

19. Length of the last word

Ideas: