leetcode 18

[Java] LeetCode 67 : Add Binary

LeetCode # 67 Given two binary strings a and b, return their sum as a binary string. Example 1: Input: a = "11", b = "1" Output: "100" Constraints: 1 = 0) { result += Math.pow(2, s.length() - 1 - i) * (s.charAt(i) - 48); i--; } return result; } } Result #1 💡 2진수를 10진수로 변환하는 방법은 틀렸다. 가장 직관적으로 생각할 수 있는 방법은 2진수를 10진수로, 10진수를 2진수로 변환하여 풀이하는 것이다. 하지만 이 방법은 틀렸다. 자료형의 범위때문에 잘못된 값이 출력된다. Solution #2 cla..

LeetCode/Easy 2021.05.12
728x90