2016年2月25日

Longest Common Prefix

摘要: 主要是效率问题,对于空串要及早退出降低时间。 还有字符串问题: C++中string不是以‘\0’结束的,C中是的。 如果对一个空串赋值‘\0’,此时串的size()为1。 1 class Solution { 2 3 public: 4 string longestCommonPrefix(vec 阅读全文

posted @ 2016-02-25 16:55 RenewDo 阅读(170) 评论(0) 推荐(0) 编辑

Roman to Integer

摘要: 根据罗马数的规则可以很容易写出: 1 class Solution { 2 public: 3 int romanToInt(string s) { 4 int a[4]={0},i=0; 5 if(s[i]=='M') 6 while(s[i]=='M') {a[0]++;i++;} 7 if(s 阅读全文

posted @ 2016-02-25 15:59 RenewDo 阅读(143) 评论(0) 推荐(0) 编辑

Integer to Roman

摘要: 首先是我自己看完网上的罗马数规则写的又臭又长的代码!(捂脸!!) 1 class Solution { 2 public: 3 string intToRoman(int num) { 4 string s=""; 5 int a[4]={0},i=3; 6 while(num!=0) 7 { 8 阅读全文

posted @ 2016-02-25 13:32 RenewDo 阅读(131) 评论(0) 推荐(0) 编辑

导航