Inorder iterative traversal

DoublyListNode head, previous

Skip to content
# Convert BST to Doubly Linked List

# Coins in a Line III

# Climbing Stairs II

# Longest Substring with At Most K Distinct Characters

Month: July 2017

There are n coins in a line. Two players take turns to take a coin from one of the ends of the line until there are no more coins left. The player with the larger amount of money wins.

Could you please decide the first player will win or lose?

Follow Up Question:

If n is even. Is there any hacky algorithm that can decide whether first player will win or lose in O(1) memory and O(n) time?

solution

A child is running up a staircase with `n`

steps, and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs.

Given a string s, find the length of the longest substring T that contains at most k distinct characters.

For example, Given s = `"eceba"`

, `k = 3`

,

T is `"eceb"`

which its length is `4`

.

solution