Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

leetcode patterns

If input array is sorted then
- Binary search
- Two pointers

If asked for all permutations/subsets then
- Backtracking

If given a tree then
- DFS
- BFS

If given a graph then
- DFS
- BFS

If given a linked list then
- Two pointers

If recursion is banned then
- Stack

If must solve in-place then
- Swap corresponding values
- Store one or more different values in the same pointer

If asked for maximum/minimum subarray/subset/options then
- Dynamic programming

If asked for top/least K items then
- Heap

If asked for common strings then
- Map
- Trie

Else
- Map/Set for O(1) time & O(n) space
- Sort input for O(nlogn) time and O(1) space
Comment

PREVIOUS NEXT
Code Example
Java :: first java program 
Java :: input java 
Java :: java shorthand if 
Java :: spring enable cors 
Java :: how to find the angle of 2 coordinates java 
Java :: get first 5 characters of string java 
Java :: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "this.text" is null 
Java :: android send parameters with intent 
Java :: How to compare lists of custom classes without defining equals() and hashCode()? 
Java :: spigot remove every entity 
Java :: random password generator java 
Java :: How to efficiently find the highest power of 2 dividing a given number, in Java? 
Java :: java get cunnect date time 
Java :: simple java program 
Java :: date java format 
Java :: install java 8 arch 
Java :: java output 
Java :: random number between 1 and 100 java 
Java :: java hello world 
Java :: java cheat sheet 
Java :: convert int to double with 2 decimal places java 
Java :: how to set list data to android spinner 
Java :: Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema 
Java :: Java JPanel set background color 
Java :: sort 2d array by column java 
Java :: android use attribute color programmatically 
Java :: how to add elements in array in java using for loop 
Java :: arrays sort 2d array java 
Java :: RecyclerView: No layout manager attached; skipping layout 
Java :: java example 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =