158. Previous Left Sibling

JavaScriptDOM
Is this helpful ?

medium  - accepted / - tried

Given a DOM tree and a target element, please return the previous left sibling.

Like above, the previous left sibling of green <a/> is the blue <button/>. Notice that they don't necessarily have the same parent element.

If no left sibling, then return null.

What is time & space cost of your solution ?

Let's try to solve this problem within 15 mintues.

Discuss(21)