摘要: 又一道模拟题,按照一定规律生成字符串,求第n个字符串The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"one 2, thenone 1"or1211.Given an integern, generate thenthsequence. 阅读全文
posted @ 2013-10-28 13:23 Apprentice.Z 阅读(527) 评论(0) 推荐(0) 编辑
摘要: 给定字符串a,b,分别表示两个二进制数。将a,b的二进制和以字符串形式返回。Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".思路:模拟二进制加法过程,从最低位开始难点在于进位的计算。记进位符为carry, 该位的和为numint num = a[i]-'0'+b[j]-'0'+carry;carry = num/2;num %= 2;代码 1 cl 阅读全文
posted @ 2013-10-28 13:12 Apprentice.Z 阅读(166) 评论(0) 推荐(0) 编辑