Tap here to switch tabs
Problem
Submissions

Problem: Encode Number

med
30 min
Try to solve the Encode Number problem.

Statement

Given a non negative integer num, return its binary encoding string.

The encoding maps each integer to a binary string by ordering them first by length and then lexicographically:

  • 00 maps to ""

  • 11 maps to "0"

  • 22 maps to "1"

  • 33 maps to "00"

  • 44 maps to "01"

  • 55 maps to "10"

  • 66 maps to "11"

  • 77 maps to "000"

Constraints:

  • 0≤0 \leq num ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Encode Number

med
30 min
Try to solve the Encode Number problem.

Statement

Given a non negative integer num, return its binary encoding string.

The encoding maps each integer to a binary string by ordering them first by length and then lexicographically:

  • 00 maps to ""

  • 11 maps to "0"

  • 22 maps to "1"

  • 33 maps to "00"

  • 44 maps to "01"

  • 55 maps to "10"

  • 66 maps to "11"

  • 77 maps to "000"

Constraints:

  • 0≤0 \leq num ≤109\leq 10^9