Time complexity: O(n), n = size(tree)
void preorder(TreeNode root) {
if (root == null) {
return
}
System.out.println(root.value)
preorder(root.left)
preorder(root.right)
}
void inorder(TreeNode root) {
if (root == null) {
return
}
inorder(root.left)
System.out.println(root.value)
inorder(root.right)
}
void postorder(TreeNode root) {
if (root == null) {
return
}
postorder(root.left)
postorder(root.right)
System.out.println(root.value)
}
fun preorder(root: TreeNode?) {
if (root == null) {
return
}
println(root.value)
preorder(root.left)
preorder(root.right)
}
fun inorder(root: TreeNode?) {
if (root == null) {
return
}
inorder(root.left)
println(root.value)
inorder(root.right)
}
fun postorder(root: TreeNode?) {
if (root == null) {
return
}
postorder(root.left)
postorder(root.right)
println(root.value)
}
- Hamming Distance
- Judge Route Circle
- FizzBuzz
- MaxConsecutiveOnes
- MaximumDepthofBinaryTree
- NextGreaterElementOne
- ReshapetheMatrix
- ReverseLinkedList
- ImageSmoother
- Find All Duplicates in an Array
- Ransom Note
- Count Primes
- Two Sum
- Replace Words
- Linked List Cycle
- Plus One
- Power of Four
- Merge Two Sorted Lists
- Number of 1 Bits
- LongestUncommonSubsequence
- Majority Element
- Degree of an Array
- ExcelSheetColumnNumber
- Detect Capital
- SelfDividingNumbers
- 1-bit and 2-bit Characters
- Add Digits
- Employee Importance
- Invert Binary Tree
- Binary Number with Alternating Bits
- LRU Cache
- Power of Two
- Move Zeroes
- Flood Fill
- Range Addition II
- Find the Difference
- Construct String from Binary Tree
- Maximum Binary Tree
- Complex Number Multiplication
- Intersection of Two Arrays
- Binary Tree Tilt
- Base 7
- SumOfLeftLeaves
- Power of Three
- Find Pivot Index
- Search Insert Position
- Roman to Integer
- Valid Anagram
- Teemo Attacking
- Reverse Integer
- Longest Common Prefix
- Counting Bits
- Reverse Vowels of a String
- Is Subsequence
- Min Stack
- Find Largest Value in Each Tree Row
- Kth Smallest Element in a BST
- Daily Temperatures
- Two Sum IV - Input is a BST
- Single Number
- Student Attendance Record I
- Same Tree
- Assign Cookies
- Construct the Rectangle
- Jewels and Stones
- Unique Morse Code Words
- Number of Lines To Write String
- Shortest Distance to a Character
- Merge Two Binary Trees
- Subdomain Visit Count
- Island Perimeter
- Partition Labels
- Max Increase to Keep City Skyline
- Binary Search Tree to Greater Sum Tree
- Insert into a Binary Search Tree
- Defanging an IP Address
- Range Sum of BST
- To Lower Case
- Find Common Characters
- K-diff Pairs in an Array
- Available Captures for Rook
- Occurrences After Bigram
- Minimum Add to Make Parentheses Valid
- Fibonacci Number
- Number of Recent Calls
- DI String Match
- Middle of the Linked List
- Contains Duplicate
- Distance Between Bus Stops
- Letter Tile Possibilities
- Unique Paths
- Unique Number of Occurrences
- SortArrayByParity
- Sort Array By Parity II
- N-th Tribonacci Number
- N-ary Tree Level Order Traversal
- Reverse Only Letters
- Split a String in Balanced Strings
- Delete Columns to Make Sorted
- Lemonade Change
- Maximize Sum Of Array After K Negations
- Maximum Depth of N-ary Tree
- Distribute Candies to People
- Cells with Odd Values in a Matrix
- Search in a Binary Search Tree
- N-ary Tree Postorder Traversal
- N-ary Tree Preorder Traversal
- Letter Case Permutation
- Find Bottom Left Tree Value
- Matrix Cells in Distance Order
- Maximum Number of Balloons
- Complement of Base 10 Integer
- Positions of Large Groups
- ClimbingStairs
- Find the Town Judge
- Valid Parentheses
- Remove Element
- Add Two Numbers
- Longest Palindrome
- Longest Substring Without Repeating Characters
- Integer to Roman
- Container With Most Water
- Palindrome Number
- Last Stone Weight
- Minimum Path Sum
- Trapping Rain Water
- Number of Islands
- 3Sum
- 3Sum Closest
- MaximumSubArray
- Minimum Size Subarray Sum
- Flatten Nested List Iterator
- Palindrome Permutation
- Max Stack
- Merge k Sorted Lists
- Car Pooling
- Meeting Rooms II
- Subarray Sum Equals K
- Most Common Word
- Top K Frequent Elements
- String Compression
- K Closest Points to Origin
- Minimum Remove to Make Valid Parentheses
- Cousins in Binary Tree
- Kids With the Greatest Number of Candies
- Count Square Submatrices with All Ones
- Maximal Square
- Subtract the Product and Sum of Digits of an Integer
- Two Sum II - Input array is sorted
- House Robber
- Max Area of Island
- Binary Search Tree Iterator
- Add Two Numbers II
- Binary Tree Zigzag Level Order Traversal
- Shuffle the Array
- Remove Vowels from a String
- Number of Steps to Reduce a Number to Zero
- Single-Row Keyboard
- Maximum Subarray
- Running Sum of 1d Array
- Create Target Array in the Given Order
- Find All The Lonely Nodes
- Find N Unique Integers Sum up to Zero
- Target Sum
- Relative Sort Array
- Univalued Binary Tree
- High Five
- Longest Palindromic Subsequence
- Nested List Weight SumNested List Weight Sum
- XOR Operation in an Array
- Minimum Time Visiting All Points
- How Many Numbers Are Smaller Than the Current Number
- Find Numbers with Even Number of Digits
- Decompress Run-Length Encoded List
- Path Sum
- SumOfDigitsInTheMinimumNumber
- Palindrome Linked List
- Palindromic Substrings
- Moving Average from Data Stream
- Contains Duplicate II
- Time Based Key-Value Store
- Lowest Common Ancestor of a Binary Tree
- Binary Tree Maximum Path Sum
- Find Minimum in Rotated Sorted Array
- Find First and Last Position of Element in Sorted Array
- Word Search II
- Search a 2D Matrix II
- Binary Tree Inorder Traversal]
- Insert Interval
- Sort List
- Remove Duplicates from Sorted Array II
- First Unique Character in a String
- Largest Rectangle in Histogram
- Next Permutation
- Missing Number
- Shortest Unsorted Continuous Subarray
- House Robber III
- Implement Trie (Prefix Tree)
- Rotate Image
- Binary Tree Level Order Traversal
- Sort Colors
- Intersection of Two Linked Lists
- Binary Tree Vertical Order Traversal
- NQueen
- Logger Rate Limiter
- Find Duplicate File in System
- Valid Palindrome
- Add and Search Word - Data structure design
- Closest Binary Search Tree Value
- Path Sum II
- Path Sum III
- Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock with Cooldown
- Find All Numbers Disappeared in an Array
- Convert Sorted Array to Binary Search Tree
- Backspace String Compare Easyme-to-buy-and-sell-stock-with-cooldown/)
- Game of Life
- Distribute Candies to People
- Friend Circles
- Robot Bounded In Circle
- Clone Graph
- Remove Duplicates from Sorted Array
- Remove Linked List Elements
- Remove All Adjacent Duplicates In String
- Remove All Adjacent Duplicates in String II
- Find Anagram Mappings
- Average of Levels in Binary Tree
- Hit Counter
- Binary Tree Right Side View
- Binary Tree Paths
- Convert Sorted List to Binary Search Tree
- Word Pattern
- All Elements in Two Binary Search Trees
- Sum of Root To Leaf Binary Number
- Bulls And Cows
- Walls and Gates
- Spiral Matrix II
- Merge Intervals
- Maximum Length of Repeated Subarray
- Inorder Successor in BST
- Inorder Successor in BST Two
- Count And Say
- Implement strStr()
- Rotate Array
- Unique Paths III
- Vertical Order Traversal of a Binary Tree
- Car Pooling
- Swap Nodes in Pairs
- Transpose Matrix
- Gas Station
- LFU Cache
- Permutation in String
- Smallest Subtree with all the Deepest Nodes
- Minimum Depth of Binary Tree
- Longest Substring with At Most K Distinct Characters
- Intersection of Two Arrays II
- WordBreak
- Letter Combinations of a Phone Number
- Perform String Shifts
- Group Shifted Strings
- Remove Covered Intervals
- Maximum Distance in Arrays
- Rotate List
- Binary Search
- Two Sum III - Data structure design
- Minimum Number of Arrows to Burst Balloons
- Buddy Strings
- House Robber II
- Search a 2D Matrix
- Repeated DNA Sequences
- Armstrong Number
- Lowest Common Ancestor of a Binary Search Tree
- Minimum Domino Rotations For Equal Row
- Minimum Domino Rotations For Equal Row
- Search in a Sorted Array of Unknown Size
- Consecutive Characters
- Meeting Rooms
- Two Sum Less Than K
- Valid Mountain Array
- Reorganize String
- Binary Gap
- Network Delay Time
- Unique Paths II
- Remove Duplicates from Sorted List II
- Count Sorted Vowel Strings
- Tuple with Same Product
- Find if Path Exists in Graph
- Number of Operations to Make Network Connected
- Find Center of Star Graph
- All Paths From Source to Target
- Minimize Maximum Pair Sum in Array
- Deepest Leaves Sum
- Balance a Binary Search Tree
- Jump Game III
- Remove Nth Node From End of List
- Reverse Bits
- Minimum Operations to Make the Array Increasing
- Minimum Cost to Move Chips to The Same Position
- Spiral Matrix
- Concatenation of Array
- Minimum Number of Operations to Move All Balls to Each Box
- Watering Plants
- Partitioning Into Minimum Number Of Deci-Binary Numbers