Skip to content

Commit 75c0cd6

Browse files
committed
docs: add algorithm description for last stone weight
1 parent b0ae1eb commit 75c0cd6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/easy/last_stone_weight.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ fn last_stone_weight(stones: Vec<i32>) -> i32 {
1313
*max_heap.peek().unwrap_or(&0)
1414
}
1515

16+
/*
17+
Algorithm - Heap
18+
19+
Time O(NlogN)
20+
Space O(N)
21+
22+
Description:
23+
1. Create a max heap
24+
2. Pop 2 items from the heap
25+
3. If they are not equal, push the difference to the heap
26+
4. Repeat 2-3 until the heap has 1 or 0 items
27+
5. Return the top item of the heap
28+
29+
30+
*/
31+
1632
#[cfg(test)]
1733
mod tests {
1834
use super::*;

0 commit comments

Comments
 (0)