The overall rhythm

  • Fast hand each round of interview rhythm is relatively fast, can quickly enter the next round
  • Each round has a corresponding algorithm problem, but they are all basic problems
  • Do not be timid in the face of algorithm questions, brush 150 questions in advance, generally there will be no problem

Side – longest ascending subsequence length

Given an unordered array of integers, find the length of the longest ascending subsequence.

Example: input: [10,9,2,3,7,101,99,100] output: 4 explanation: the longest ascending subsequence is [2,3,7,101], which has a length of 4.

// Elements are contiguous; If the elements are not contiguous, the dp solution can be used
public static void main(String[] args) {
    int[] temp = new int[] {10.9.2.3.7.12.99.100};
    int max = 0;
    for(int x= 0; x < temp.length-1; x++){int result = 1;
        for(int y = x+1; y < temp.length; y++){if(temp[y] > temp[y-1]){
                result++; 
            }else{
                result=0; }}if(result > max){
            max = result;
        }
    }
    System.out.println(max);       
}     
Copy the code

Two sides – reverse linked list

Ask to invert the list, give the head node of the node, ask to return the invert list. Leetcode Title address ListNode structure is as follows:

class ListNode {
    int val;
    ListNode next;
    ListNode() {
    }
    ListNode(int val) {
        this.val = val;
    }
    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next; }}Copy the code

The inversion code is as follows:

// The main use of intermediate variables to achieve inversion
public ListNode reverseList(ListNode head) {
    ListNode prev = null;
    ListNode curr = head;
    while(curr ! =null) {
        ListNode next = curr.next;
        // Change the direction
        curr.next = prev;
        // These two rows can be thought of as moving forward
        prev = curr;
        curr = next;
    }
    return prev;
}  
Copy the code

Three sides – An element that appears once

Given an array of non-empty integers, each element appears twice except for one element. Find the element that appears only once.

Leetcode Subject address

The original way

public int singleNumber(int[] nums) {
    int res = 0;
    Set<Integer> set = new HashSet<>();
    for (int x : nums) {
        if (set.contains(x)) {
            set.remove(x);
        } else {
            set.add(x);
        }
    }
    res = set.stream().findFirst().get();
    return res;
}
Copy the code

An operation

 public int singleNumber(int[] nums) {
    int single = 0;
    for (int num : nums) {
        single ^= num;
    }
    return single;
 }
Copy the code