Given a binary tree, return the *postorder* traversal of its nodes’ values.

For example:

Given binary tree `{1,#,2,3}`

,

1 \ 2 / 3

return `[3,2,1]`

.

**Note:** Recursive solution is trivial, could you do it iteratively?

Skip to content
# Category: leetcode

Binary Tree · Depth First Search · DFS · leetcode · Stack · Traversals · Trees## Binary Tree Postorder Traversal

Binary Tree · Depth First Search · DFS · leetcode · Stack · Traversals · Trees## Binary Tree Preorder Traversal

Binary Tree · Depth First Search · DFS · leetcode · Stack · Traversals · Trees## Binary Tree Inorder Traversal

leetcode · Linked List## Odd Even Linked List

leetcode · Linked List## Reorder List

leetcode · Linked List## Copy List with Random Pointer

leetcode · Linked List## Intersection of Two Linked Lists

leetcode · Linked List## Remove Linked List Elements

leetcode · Linked List## Reverse Linked List II

leetcode · Linked List## Partition List

Given a binary tree, return the *postorder* traversal of its nodes’ values.

For example:

Given binary tree `{1,#,2,3}`

,

1 \ 2 / 3

return `[3,2,1]`

.

**Note:** Recursive solution is trivial, could you do it iteratively?

Given a binary tree, return the *preorder* traversal of its nodes’ values.

For example:

Given binary tree `{1,#,2,3}`

,

1 \ 2 / 3

return `[1,2,3]`

.

**Note:** Recursive solution is trivial, could you do it iteratively?

Given a binary tree, return the *inorder* traversal of its nodes’ values.

For example:

Given binary tree `[1,null,2,3]`

,

1 \ 2 / 3

return `[1,3,2]`

.

**Note:** Recursive solution is trivial, could you do it iteratively?

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.

You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity.

**Example:**

Given `1->2->3->4->5->NULL`

,

return `1->3->5->2->4->NULL`

.

**Note:**

The relative order inside both the even and odd groups should remain as it was in the input.

The first node is considered odd, the second node even and so on …

Given a singly linked list *L*: *L*_{0}→*L*_{1}→…→*L*_{n-1}→*L*_{n},

reorder it to: *L*_{0}→*L*_{n}→*L*_{1}→*L*_{n-1}→*L*_{2}→*L*_{n-2}→…

You must do this in-place without altering the nodes’ values.

For example,

Given `{1,2,3,4}`

, reorder it to `{1,4,2,3}`

.

A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.

Return a deep copy of the list.

Write a program to find the node at which the intersection of two singly linked lists begins.

For example, the following two linked lists:

A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1 → b2 → b3

begin to intersect at node c1.

**Notes:**

- If the two linked lists have no intersection at all, return
`null`

. - The linked lists must retain their original structure after the function returns.
- You may assume there are no cycles anywhere in the entire linked structure.
- Your code should preferably run in O(n) time and use only O(1) memory.

Remove all elements from a linked list of integers that have value ** val**.

**Example**

* Given:* 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6,

Reverse a linked list from position *m* to *n*. Do it in-place and in one-pass.

For example:

Given `1->2->3->4->5->NULL`

, *m* = 2 and *n* = 4,

return `1->4->3->2->5->NULL`

.

**Note:**

Given *m*, *n* satisfy the following condition:

1 ≤ *m* ≤ *n* ≤ length of list.

Given a linked list and a value *x*, partition it such that all nodes less than *x* come before nodes greater than or equal to *x*.

You should preserve the original relative order of the nodes in each of the two partitions.

For example,

Given `1->4->3->2->5->2`

and *x* = 3,

return `1->2->2->4->3->5`

.