734. Convert Binary to Decimal
You are given a binary number N (represented as a string or integer). Your task is to convert it into its corresponding decimal (base-10) number.
Example 1:
Input: N = "1011"
Output: 11
Explanation: 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 8 + 0 + 2 + 1 = 11
Example 2:
Input: N = "100"
Output: 4
Explanation: 1×2² + 0×2¹ + 0×2⁰ = 4 + 0 + 0 = 4
Now Your Turn!
Pick the correct output for the given inputInput: N = "111111"
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= len(N) <= 30
- N contains only characters '0' or '1' (if input is string)
- Leading zeros may exist (e.g., "000101" → 5)