上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 23 下一页
摘要: 原题地址辅助栈代码: 1 bool isValid(string s) { 2 stack st; 3 4 for (auto c : s) { 5 if (st.empty()) 6 st.p... 阅读全文
posted @ 2015-02-02 19:21 李舜阳 阅读(156) 评论(0) 推荐(0)
摘要: 原题地址如果不使用额外的空间,可以先将A数组整体向后挪n个单位,然后开始常规的merge操作代码: 1 void merge(int A[], int m, int B[], int n) { 2 int i = m - 1; 3 int j = 0; 4 ... 阅读全文
posted @ 2015-02-02 19:05 李舜阳 阅读(127) 评论(0) 推荐(0)
摘要: 原题地址注意从1开始索引,所以记得+1代码: 1 int titleToNumber(string s) { 2 int res = 0; 3 4 for (int i = 0; i < s.length(); i++) { 5 ... 阅读全文
posted @ 2015-02-02 18:53 李舜阳 阅读(156) 评论(0) 推荐(0)
摘要: 原题地址26进制数注意,编号是从1开始的,所以取模取商之前要-1代码: 1 string convertToTitle(int n) { 2 string res; 3 4 while (n) { 5 res = (char)... 阅读全文
posted @ 2015-02-02 18:46 李舜阳 阅读(119) 评论(0) 推荐(0)
摘要: 原题地址先将A链末尾和B链头部接起来然后判断是否有环,如果无环,说明肯定不想交,如果有环,那么相交的位置就是环开始的位置第一遍做的时候没遇到什么问题,第二遍做的时候各种出错,后来发现原来在用快慢指针法的时候快慢指针要从起点开始,否则计算出来的第一个相交位置不是环开始的位置。。代码: 1 ListNo... 阅读全文
posted @ 2015-02-02 18:22 李舜阳 阅读(169) 评论(0) 推荐(0)
摘要: 原题地址找规律题代码: 1 string convert(string s, int nRows) { 2 string res; 3 4 if (nRows <= 1) 5 return s; 6 7 ... 阅读全文
posted @ 2015-02-02 16:57 李舜阳 阅读(145) 评论(0) 推荐(0)
摘要: 原题地址非常恶心的一道题,又是处理溢出问题根据经验,处理溢出问题应该:优先在还没溢出的时候检测运算后的结果是否会溢出,而不是等到溢出以后再去判断结果是否溢出比如,为了判断F(x)是否会溢出,应该推算出x的合法范围,当x不在合法范围内时,判定溢出。而不是计算出F(x)的值之后再判断是否会溢出。有时候计... 阅读全文
posted @ 2015-02-02 16:26 李舜阳 阅读(206) 评论(0) 推荐(0)
摘要: 原题地址注意溢出问题代码: 1 int reverse(int x) { 2 int newx = 0; 3 4 while (x) { 5 if ((newx * 10 / 10) != newx) 6 ... 阅读全文
posted @ 2015-02-02 15:56 李舜阳 阅读(126) 评论(0) 推荐(0)
摘要: 原题地址方法I:传统的判断回文的方法,左右指针,不断收缩判断方法II:将数字翻转,判断翻转后的数字是否相等,溢出也没关系因为溢出以后更加不可能相等了代码(方法II): 1 bool isPalindrome(int x) { 2 int oldx = x; 3 int... 阅读全文
posted @ 2015-02-02 15:38 李舜阳 阅读(135) 评论(0) 推荐(0)
摘要: 原题地址isalnum:判断是否是字符或数字toupper:将字符转换成大写,非字符不变代码: 1 bool isPalindrome(string s) { 2 string news; 3 for (auto c : s) 4 if (is... 阅读全文
posted @ 2015-02-02 15:28 李舜阳 阅读(123) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 23 下一页