Hey everyone. Check out this in-depth solution for leetcode 113.
Пікірлер: 4
@sajalgupta73452 жыл бұрын
Hey Andy, Why did we do slate.slice() on line 23. Wouldn't slate and slate.slice() be the same thing as both will returns the array only.
@sourenasahraian20552 жыл бұрын
They are but only at that point, Arrays are passed around by reference , so any change you do the same slate instance as it gets passed around up and down the tree(future push /pop ) are also reflected into the result . You want your hard earned path solutions to be snapshots in time and remain intact . If you don't copy the array , the same address in memory gets passed around and your data will get corrupt.
@TekkenRoom Жыл бұрын
that's also an alternative line " paths.push([...slate])"