Previous Left Sibling
2022年5月1日小于 1 分钟
Previous Left Sibling
Question
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 ?
Code
/**
* @param {Element} root
* @param {Element} target
* @return {Elemnt | null}
*/
function previousLeftSibling(root, target) {
// your code here
}