Tuesday, June 4, 2013

Add Binary@leetcode

Given two binary strings, return their sum (also a binary string).

For example,
a = "11"
b = "1"
Return "100".

Few points here:
1. Pay attention to the side condition, such as the beginning of the string is 0.
2. Read the string should in back order. And after pushing all the digits in string, we should return the reverse one.

No comments:

Post a Comment

Leetcode 316. Remove Duplicate Letters

 这道题表面问的是如何删除重复,实际在问如何从多个字符选取一个保留,从而让整个字符串按升序排列。那么策略就是对于高顺位的字符比如‘a',就要选靠前位置的保留,而低顺位字符如’z'则应该尽量选取靠后位置保留。 算法大概思路:每看到一个字符,我们要决定是否保留 1. ...