- 博客(7)
- 资源 (7)
- 收藏
- 关注
原创 Remove Nth Node From End of List
由于一般的链表不包含表头,所以使得处理第一个节点相较于其他节点具有特殊性,所以我的思路是先转化为含表头的的链表,再进行操作,最后还原成没有表头的链表,并返回。#include using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x): val(x), next(NULL) {} }; c
2015-05-13 21:00:29 445
原创 Longest Common Prefix
本题并没有太大的难度,有两点值得记忆:其一:由于用到vector容器,所以应包含头文件vector;其二:vector不支持初始化列表方式初始化,即vector strs = {"abcdef", "abcdrgh", "abcthu"}会导致编译出错。 #include #include #include using namespace std; class Solution { publi
2015-05-12 22:00:48 410
原创 Palindrome Number
今天编写代码超没有感觉,本道题并不难,但在编写的过程中每敲一个字符,都感觉到违和感。路漫漫其修远兮,淡定,要坐得住。 #include using namespace std; class Solution { public: bool isPalindrome(int x) { if(x < 0) return false; int tmp = x; if(tm
2015-05-11 22:02:47 357
原创 String to Integer (atoi)
首先根据位数初步判断待转换的数是否超过int数据类型的表示范围,接着用long long类型承载待转换的数,判断是否超过int数据类型的范围,最后将long long类型变量承载的数赋值给int类型的变量。这里编译器会发出警告,数据丢失。暂时忽略,以后继续研究。#include #include #include using namespace std; class Solution { pub
2015-05-10 15:40:35 631
原创 ZigZag Conversion
解决本题时本地测试通过,但在提交代码时出现memory limit exceed。原因是并未考虑输入numRows为小于等于1的情况。#include #include using namespace std; class Solution { public: string convert(string s, int numRows) { if(numRows <= 1) re
2015-05-08 14:46:36 398
原创 Reverse Integer
对于有符号int类型的整数,其取值范围为-2^31~2^31-1,即-2147483648~2147483647,所以当输入为-2147483648时并不能这样做:int a; a = -x;即不能像其他负数那样直接取反,需要单独处理。 #include using namespace std; class Solution { public: int reverse(int
2015-05-08 14:35:34 377
原创 归并排序代码实现
由于所选weiss教材上的归并算法p175比较复杂,各个函数之间相互调用导致逻辑混乱,索性自己写了一个int *mergeSort(int *a, int N) { int *reArray = new int[N]; int *temp1,*temp2; int i = 0, j = 0, k = 0; int length1,length2; if(1 == N) { reArr
2015-05-05 10:19:09 454
The Algorithm Design Manual-Steve S. Skiena Second Edition
2015-07-08
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人