Rust Day 15: Leetcode — Single Number

Arjun Sunil Kumar
Go Rust
Published in
2 min readMay 4, 2022

A quick post for today.

Problem:

Logic:

Bitwise XOR on all the numbers gives you the number that is not yet paired.

Code:

Syntax:

  1. fold(): similar to map + reduce functions.
https://rust-unofficial.github.io/patterns/patterns/creational/fold.html
https://doc.rust-lang.org/std/iter/trait.Iterator.html

Here you can see, filter also being used.

We need to use iter() before using these operators. Iter is similar to stream() in Java.

Apparently, it is part of Design Patterns in RUST.

https://rust-unofficial.github.io/patterns/patterns/creational/fold.html

the first argument ie 0i32 is the initial value.

the second argument is a closure

2. Closure: Similar to lambda functions

https://doc.rust-lang.org/rust-by-example/fn/closures.html
https://medium.com/coding-rust/best-explanation-of-closure-in-rust-2b20210eba53

3. 0i32 : we can directly declare the numerical as i32, by appending the datatype to the last instead of 0 as i32

Reference:

Found it Interesting?

Please show your support by 👏

--

--

Arjun Sunil Kumar
Go Rust

Writes on Database Kernel, Distributed Systems, Cloud Technology, Data Engineering & SDE Paradigm. github.com/arjunsk