Autumn Recruitment Exam Preparation - Summary of Huawei's High-frequency Questions in the Past 6 Months


Article directory


foreword

I only record my experience in preparing Leetcode. You can refer to most of the questions you have done. There are
22 questions in total.


1. leetcode 45. Jumping Game II -java version

2. Leetcode 101. Symmetric binary tree-java implementation

Original link

3. 349. Intersection of two arrays

4. Leetcode 205. Isomorphic string-java implementation

I didn't understand this question at first

5. Leetcode Weekly Competition 2386. Find the Kth largest sum of an array - java implementation

This question is the most difficult to understand

6. Leetcode 102. Level order traversal of binary tree - java implementation

Seven, leetcode 1669. Merge two linked lists - java implementation

8. Sword Pointer Offer II 074. Merge interval

The array intervals represents a collection of several intervals, and a single interval is intervals[i] = [starti, endi]. Please merge all overlapping intervals and return an array of non-overlapping intervals that exactly covers all intervals in the input.

Input: intervals = [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Explanation: The intervals [1,3] and [2,6] overlap, merge them into [1,6].

This question has been similarly sorted by numbers first and then divided into two situations, and finally remember to count the last group

class Solution {
    
    
    public int[][] merge(int[][] a) {
    
    
       // Arrays.sort(intervals,(o1,o2)->(o1[0] == o2[0] ? o1[1]-o2[1]:o1[0]-o2[0]));
         List<int[]> res = new ArrayList<>();
           if(a.length ==0 ) return null;
           Arrays.sort(a, (i1, i2) -> (i1[0] == i2[0] ? i2[1] - i1[1] : i1[0] - i2[0]));
           int l = a[0][0] ;int r  = a[0][1];//第一个区间的左右端点
           //从第二个端点开始遍历
           for(int i = 1 ; i < a.length ; i++){
    
    
               if(a[i][0] > r ){
    
    
                   res.add(new int[]{
    
    l,r});
                   l = a[i][0];
                   r = a[i][1];
               }else r = Math.max(r,a[i][1]);
           }
           //最后一个区间要保存
           res.add(new int[]{
    
    l,r});
           return res.toArray(new int[0][0]) ;
 
    }
}

Nine, leetcode 54. Spiral matrix-java implementation

leetcode 59. Spiral matrix II-java implementation

10. Sword Pointer Offer II 056. The sum of two nodes in the binary search tree

Given the root node root of a binary search tree and an integer k, please judge whether there are two nodes whose sum is equal to k in the binary search tree. Assume that the values ​​of the nodes in the binary search tree are all unique.

Input: root = [8,6,10,5,7,9,11], k = 12
Output: true
Explanation: The sum of node 5 and node 7 is equal to 12

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    
    
    Set<Integer> s = new HashSet<>();
    public boolean findTarget(TreeNode root, int k) {
    
    
        if(root == null) return false ;
         if(s.contains(k - root.val)) return true;
        s.add(root.val);
        return findTarget(root.left,k)||findTarget(root.right,k);
    }
}

11. Jianzhi offer 32. Adjust the order of the array so that the odd number is in front of the even number-java version

12. Edit distance

Thirteen, 705. Design hash collection

Fourteen, leetcode 208. Realize Trie (prefix tree) - java problem solution

15. Sword Pointer Offer II 024. Reverse Linked List

16. Leetcode's longest string without repeated characters - Java realizes the third question

Seventeen, 146. LRU cache

Eighteen, 328. Parity linked list

19. 213. Robbery II

Do two DPs in a ring

20. 912. Sorting arrays

Use quick sort, but merge sort also needs to be mastered

21, 20. Valid parentheses

the stack

22. 198. Robbery

dynamic programming

Guess you like

Origin blog.csdn.net/qq_41810415/article/details/130332244