A better algorithm related to the article Java language __ face questions

Source: Internet
Author: User
Tags array sort array to string data structures rotate image

This explains the common algorithms and data structures for interviewing from the Java perspective: strings, lists, trees, graphs, sorting, recursion vs. iterations, dynamic programming, bit manipulation, probability problems, permutation combinations, and some topics that need to be looked at regularly.

1. String and array

strings and arrays are the most common types of interview topics and should be assigned the maximum time.

The first thing to note about strings is that unlike C + +, Java strings are not char arrays. Without the automatic completion of IDE code, you should keep in mind the following common methods.

ToCharArray ()///get string corresponding char array
arrays.sort ()  ///array sort
arrays.tostring (char[] a)//array to string
charAt ( int x)//Get character length at an index
()//String length
//array size
substring (int beginindex) 
substring (int beginindex, int endindex)
integer.valueof ()//string to Integer
string.valueof ()/integer to String

The strings and arrays themselves are simple, but the related topics require more complex algorithms to solve. such as dynamic planning, search, and so on.

Classic topics:
0) Rotate Array
1) Evaluate Reverse Polish notation (Stack)
2) Longest palindromic Substring (DP)
3 Word Break (DP)
3 Word Break II (DP, DFS)
4 Word Ladder (Queue, BFS)
5) Median of two Sorted Arrays
6) Regular Expression Matching
7) Merge intervals
8) Insert Interval
9) Two Sum
9) Two Sum ii–input array is sorted
9) Two Sum iii-data structure design
9) 3Sum
9) 4Sum
Ten) 3Sum closest
One) String to Integer
) Merge Sorted Array
Valid parentheses
) Implement STRSTR ()
Set Matrix Zeroes
Search Insert Position
) Longest consecutive Sequence
) Valid palindrome
) Spiral Matrix
Search a 2D Matrix
Rotate Image [Palantir]
Triangle)
) Distinct subsequences Total
Maximum Subarray [Palantir, LinkedIn]
Maximum Product Subarray [LinkedIn]
Remove Duplicates from Sorted Array
-Remove duplicates from Sorted Array II
Longest Substring without repeating Characters
Longest Substring that contains 2 unique characters [Google]
) Palindrome Partitioning
) Palindrome Partitioning II
Reverse Words in a String
Find Minimum in rotated Sorted Array
Find Minimum in rotated Sorted Array II
Find Peak Element
Min Stack
Majority Element
Combination Sum (DFS)
Combination Sum II (DFS)
best time to buy and Sell-stock
best time to buy and Sell-stock II
Sell stock III (DP)
Sell stock IV (DP)
Notoginseng) Longest Common Prefix [Google]
Largest number
Combinations (DFS)
Compare Version Numbers
) Gas station
Candy [Google]
) Jump Game
Pascal ' s triangle
Pascal ' s triangle II
Container with Most Water
) Count and Say
) Repeated DNA sequences
) House robber
Dungeon Game (DP)
Number of Islands (DFS/BFS)
Wuyi) surrounded regions (BFS)
Max Points on a line
Letter combinations of a Phone number (DFS)
) Remove Element
anagrams)
Search for a Range
Simplify Path
) Isomorphic Strings
Minimum Size Subarray Sum
Minimum Path Sum (DP)
) Unique Paths (DP)

2. Linked list

In Java, the implementation of a linked list is very simple, each node has a value Val and a link to the next node next.

Class Node {
	int val;
	Node Next;
 
	Node (int x) {
		val = x;
		next = null;
	}
}


The list two well-known applications are stack stack and queue queues. There are implementations in the Java standard library, one is stack, and the other is LinkedList (queue is the interface it implements).

Classic topics:

1) Add two Numbers
2) Reorder List
3) Linked List Cycle
4 Copy List with Random pointer
5) Merge two Sorted Lists
6) Merge k Sorted Lists *
7) Remove duplicates from Sorted List
8) Partition List
9) LRU Cache
Intersection of two linked Lists
Remove linked List Elements
) Swap Nodes in pairs
Reverse linked List

3. Tree

The tree here usually refers to the two fork tree, each node contains a left child node and the right child node, as follows:

Class treenode{
	int value;
	TreeNode left;
	TreeNode right;

The following are some of the concepts associated with trees:

Binary search tree: node <= right node in the left node <=.
Balance vs. Non-equilibrium: In a balanced binary tree, the depth of the left and right subtrees of each node varies by up to 1 (1 or 0).
Full two-Binary tree: There are two children in every node except the leaf node.
Perfect binary (Perfect Binary tree): is a two-forked tree with the following properties: All leaf nodes have the same depth or level, and each parent node must have two children.
Complete binary trees (Complete Binary tree): In a two-forked tree, each layer may be fully filled except for the last, and all nodes must be as left-leaning as possible.

Classic topics:

1) Binary Tree Preorder traversal
2) Binary tree inorder traversal [Palantir]
3) Binary Tree Postorder Traversal
4) Binary Tree level order traversal
4) Binary Tree level order traversal II
5) Validate Binary Search Tree
6) Flatten Binary tree to linked List
7) Path Sum (DFS or BFS)
7 Path Sum II (DFS)
8) construct Binary tree from inorder and postorder traversal
9 Convert Sorted Array to Binary Search tree
Convert Sorted List to Binary Search tree
One) Minimum Depth of Binary Tree
Binary Tree Maximum Path Sum *
Balanced Binary Tree
) Symmetric tree
Binary Search Tree Iterator
Binary Tree Right Side View
Implement Trie (Prefix)
ADD and Search word-data structure design (DFS)

4. Figure

The issues related to the graph are mainly focused on depth-first search (depth) and breadth-first search (breath). Depth-First search is simple, and breadth first takes care to use queue. Here is a simple use of queue queues to achieve breadth-first search.

public class Graphtest {public static void Breathfirstsearch (Graphnode root, int x) {if (Root.val = =
 
		x) System.out.println ("Find in Root");
		Queue queue = new Queue ();
		Root.visited = true;
 
		Queue.enqueue (root);
			while (Queue.first!= null) {Graphnode c = (Graphnode) queue.dequeue (); For (Graphnode N:c.neigh 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.