636. Encode Number

Given a non-negative integer num, Return its encoding string.

The encoding is done by converting the integer to a string using a secret function that you should deduce from the following table:

Example 1:

Input: num=23

Output: "1000"

Explanation:

num + 1 = 24

Binary of 24 → 11000

Remove leading 1 → 1000

Example 2:

Input: num=107

Output: "1101010"

Explanation:

num + 1 = 108

Binary of 108 → 1101100

Remove leading 1 → 101100

Now Your Turn!

Pick the correct output for the given input

Input: num=31

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 0<=num<=109

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
string encode(int num) {
//Your Code Goes Here
}
};
Test Case

Input:

Num