Banner generated with leetcode.jacoblin.cool
Here are my Leetcode solutions, all in Rust 🦀
The main branch exclusively contains working solutions.
I'm working through the Top Interview 150, it's fun and covers a lot of topics. Keep those linked lists and trees fresh.
Q: Why use Rust for Leetcode?
A: Rust's type system and ownership rules help prevent a lot of "stupid shit" like null pointers and OOB exceptions, which means I can focus more on writing actual problem-solving logic.
Rust also features first-class unit tests, so I can write challenge tests (i.e., "given these inputs, I expect this output") alongside my source code and run them locally in the terminal.
Q: Rust is cool! How can I start learning?
A: Start your Rust journey right here!
Q: Can you explain <code segment>?
A: See above.
Q: Why the weird function signatures?
A: TLDR: it's LeetCode's fault, and I would change them if I could.
LeetCode's Rust support is rough around the edges. You can't change much about the provided function signatures; I think all you're allowed is adding/removing mut keywords. For example, in most cases, a provided function argument typed Vec<i32> should technically be redefined as a slice &[i32], but LeetCode disallows that type of modification.
Q: What is #[allow(clippy::needless_pass_by_value)]?
A: TLDR: See above.
This is an attribute that instructs the code linter (clippy) to quit bothering me about inefficient parameter typing. I employ this for LeetCode function signatures that I'm not allowed to change. Click here for more info on the lint.
Q: I found a curse word in the source code. Can you remove it?
A: That's my bad. I'll remove it right away
- 0136: Single Number
- 0200: Number of Islands