Problem
Given a binary tree, return the preorder traversal of its nodes’ values.
Example:
1 |
|
Follow up: Recursive solution is trivial, could you do it iteratively?
Given a binary tree, return the preorder traversal of its nodes’ values.
Example:
1 |
|
Follow up: Recursive solution is trivial, could you do it iteratively?
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You may not modify the values in the list’s nodes, only nodes itself may be changed.
Example 1:
1 |
|
Example 2:
1 |
|
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.
Note: Do not modify the linked list.
Example 1:
1 |
|
Example 2:
1 |
|
Example 3:
1 |
|
Follow-up:
Can you solve it without using extra space?
Given a linked list, determine if it has a cycle in it.
To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.
Example 1:
1 |
|
Example 2:
1 |
|
Example 3:
1 |
|
Follow up:
Can you solve it using O(1) (i.e. constant) memory?
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences.
Note:
Example 1:
1 |
|
Example 2:
1 |
|
Example 3:
1 |
|
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.
Note:
Example 1:
1 |
|
Example 2:
1 |
|
Example 3:
1 |
|
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.
Example 1:
1 |
|
Note:
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Example 1:
1 |
|
Example 2:
1 |
|
Given a non-empty array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Example 1:
1 |
|
Example 2:
1 |
|
There are N children standing in a line. Each child is assigned a rating value.
You are giving candies to these children subjected to the following requirements:
What is the minimum candies you must give?
Example 1:
1 |
|
Example 2:
1 |
|