摘要:
注意边界条件即可:num1表示0或者num2表示0; string multiply(string num1, string num2) { // Note: The Solution object is instantiated only once and is reused by each test case. if(num1.empty()||num2.empty()) return ""; if(num1[0]=='0'||num2[0]=='0') //ATT here return "0";... 阅读全文
摘要:
string addBinary(string a, string b) { // Note: The Solution object is instantiated only once and is reused by each test case. int m = a.size(); int n = b.size(); string res(max(m,n)+1,'0'); int i = m-1,j=n-1; int carry = 0; int k = res.si... 阅读全文
摘要:
int lengthOfLastWord(const char *s) { // Note: The Solution object is instantiated only once and is reused by each test case. const char* cur = s, *pStart; while(*cur==' ') //skip white space cur++; if(*cur=='\0') return 0; pStart = cur; ... 阅读全文