This is a creation in Article, where the information may have evolved or changed.
Java Brush Topic Basics
Write in front
Lintcode and Leetcode the benefits of brush problems: only care about the implementation of the function, do not have to deal with the corresponding input and output.
This is a great feature for most programmers, and processing input and output can sometimes take some time, especially when it comes to Golang.
The basic knowledge points that need to be mastered in brush questions are as follows:
- Java arrays, lists, and initialization
- References and pointers to Java objects
- TreeNode
- Java int maximum minimum value notation
- An example of Lintcode graph theory
Java arrays and lists, initializing
Although these are simple, they usually confuse the initialization and definition of various languages. Here's a simple record:
int a[] = {6,4,4,2,1};//orint b[] = new int[10];
Linked list:
ArrayList<Integer> fibList = new ArrayList<Integer>(); fibList.add(0); fibList.add(1);
References and pointers to Java objects
There is no concept of pointers in the Java language. Look at the following line of code:
Person p = new Person();
This line of code actually produces two things: one is the P variable, and the other is the person object.
Two variables are stored in the heap in the JVM.
If you have the following code:
Person p2 = p;
The value of the P variable is assigned to the P2 variable, that is, the address saved by the P variable is assigned to the P2 variable, so that the P2 variable and the p variable will point to the same person object in the heap memory.
So all the passing of objects involved in Java is a reference pass.
Arrays are also a special kind of reference, as are linked lists.
TreeNode and the data structures defined in the topic
public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; }}
Above is the Lintcode and leetcode commonly used TreeNode data structure, dedicated to binary tree operation.
In addition, the lists and stacks used in the topic are generally defined.
java int max value and minimum value
Sometimes the maximum and minimum values of type int are used. The exact values are hard to remember, and Java provides their calling methods:
System.out.println(Integer.MAX_VALUE); System.out.println(Integer.MIN_VALUE);
The results are printed as follows:
2147483647-2147483648
An example of Lintcode graph theory
In Min's "data Structure and algorithm", it is shown that there are four kinds of representation structures, the main two of which are adjacency matrix and adjacency linked list.
In Lintcode and Leetcode, the input of graph theory is not so complicated, it is usually a two-dimensional array.
Such as:
[ [1, 1, 0, 0, 0], [0, 1, 0, 0, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]]
At the same time, it usually attaches some words to explain the meaning of this data.