Parse binary string to int
Java
Easy
6 views
Problem Description
Task: parse a binary string (like 10110) and return integer value.
Output Format
Return value
Constraints
Assume only '0' and '1'.
Official Solution
static int parseBinary(char[] s){int v=0;for(char c:s){v=v*2+(c-'0');}return v;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!