Created
January 23, 2017 07:30
-
-
Save sghall/42eb3644db8ae48d2ea045569ec56c4a to your computer and use it in GitHub Desktop.
Count Rectangles in Wall
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reactanlgeCount(arr) { | |
const stack = []; | |
let count = 0; | |
for (let i = 0; i < arr.length; i++) { | |
const next = arr[i]; | |
while (stack.length && next < stack[stack.length - 1]) { | |
stack.pop(); | |
} | |
if (!(stack.length && stack[stack.length - 1] === next)) { | |
stack.push(next); | |
count++; | |
} | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment