Skip to content

agavrel/leetcode

Repository files navigation

Leetcode

About Leetcode

Leetcode is a very nice platform to practice algorithms. unlike most of its peers, it provides insights about the runtime and memory used by the algorithm.

Leetcode has one weekly contest and one biweekly contest.

About this repository

Solutions are provided in c++ and easily convertible into other languages. I try to explain them the best that I can.

Algorithms are divided in the following categories, with between brackets the usual difficulty:

  • Vector (easy to medium)
  • String (easy to medium)
  • Dynamic Programming (medium to hard)
  • Subarray (medium to hard)
  • Bit Manipulation (easy to hard)
void makeHash(int &hash, int letter) {
   // A 1 C 3 G 7 T 20 after & 0x3f, after >> 1 (middle + left), after &0b11 (middle) :
   // 0b00 00  1
   // 0b00 01  1
   // 0b00 11  1
   // 0b10 10  0
    int c = ((letter & 0x3f) >> 1)  & 0b11;
    hash &= 0b00111111111111111111; // avoid overflow
    hash = (hash << 2 | c); // add current letter information to value of the hash
}

What can you expect

I always try to coin the most elegant algorithms, with a runtime that will most of the time be faster than best solutions, while not giving up on memory usage.

fast C++

Recently I have switched to Rust and enjoyed it as it constantly beats C++ when it comes to runtime and memory (same algorithm as above:)

fast Rust

Anri ~ Timely

Anri Timely on Youtube

Little leetcode hack

static int lambda_0 = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();

NB: (for myself) to write an n superscript digit (power of) use following unicode:

ctrl+shift+u and then if n = 3 'b3', if n = 2 'b2', if n = 1 'b9'
ctrl+shift+u and then '2' '0' '7' and ending with n for other digits

Any remark ?

Feel free to make a pull request

Wished PR: Equivalent solutions in Rust and Golang!

About

My algorithms for leetcode

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages