Rust Day 15: Leetcode — Single Number
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:
fold()
: similar to map + reduce functions.
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.
the first argument ie 0i32 is the initial value.
the second argument is a closure
2. Closure
: Similar to lambda functions
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 👏