LeetCode With JavaScript

I do most of my LeetCoding in Python, so I will basically discuss here how to go from Python to equivalent JavaScript.

Basic data structures

Hash map

# py
d = dict()
// js
d = new Map();
d.set(key, value);
d.get(key);

Numbers

  • Max safe integer in Python = 2 ** 32 - 1

  • Max safe integer in JS = 2 ** 53 - 1

Extreme values of maxi-mini

# py
maxi = -inf
mini = inf

Use BigInt

As a rule of thumb, anything that's gonna fit in Python would fit in JS. Anything that overflows in Python, assume it overflows in JS. In JS use BigInt to handle big numbers.

Arrays

Create an array of some size with default values

Strings

Unicode

Bitwise

Sorting

Custom sort

Last updated