摘要: Find the common length part, then check with two pointers. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 *... 阅读全文
posted @ 2015-03-20 05:47 keepshuatishuati 阅读(130) 评论(0) 推荐(0) 编辑
摘要: Notes:1. Even s3 is empty string, if s1 and s2 are emtpy, then it should be true.2. Do not mess up the size of label. 1 class Solution { 2 public: 3 ... 阅读全文
posted @ 2015-03-20 04:56 keepshuatishuati 阅读(114) 评论(0) 推荐(0) 编辑
摘要: Pretty straight forward. 1 class Solution { 2 public: 3 string getRoman(int n, char ten, char five, char one) { 4 string result; 5 ... 阅读全文
posted @ 2015-03-20 04:11 keepshuatishuati 阅读(122) 评论(0) 推荐(0) 编辑
摘要: Do not forget to break the inner loop, when you find the insert position. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * ... 阅读全文
posted @ 2015-03-20 04:07 keepshuatishuati 阅读(128) 评论(0) 推荐(0) 编辑
摘要: Similar to merge intervals. But this is easier than merge interval, because every side is kind of "sorted". 1 /** 2 * Definition for an interval. 3 ... 阅读全文
posted @ 2015-03-20 03:07 keepshuatishuati 阅读(139) 评论(0) 推荐(0) 编辑
摘要: Brute Force: 1 class Solution { 2 public: 3 int strStr(char *haystack, char *needle) { 4 if (!haystack) return -1; 5 if (!needle) ... 阅读全文
posted @ 2015-03-19 23:35 keepshuatishuati 阅读(139) 评论(0) 推荐(0) 编辑
摘要: i ^ (i >> 1), that's the general format 1 class Solution { 2 public: 3 vector grayCode(int n) { 4 vector result; 5 for (int i = 0;... 阅读全文
posted @ 2015-03-19 23:20 keepshuatishuati 阅读(102) 评论(0) 推荐(0) 编辑
摘要: Nothing fancy, just use recursive. 1 class Solution { 2 public: 3 void getP(vector &result, string current, int left, int right) { 4 if (l... 阅读全文
posted @ 2015-03-19 23:18 keepshuatishuati 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Not quite hard. Just remember initialize index to 0. Because if you initialize it as -1 and all the gas satisfy the cost, it will return -1.Actually, ... 阅读全文
posted @ 2015-03-19 23:15 keepshuatishuati 阅读(122) 评论(0) 推荐(0) 编辑
摘要: Notes:1. When numerator is 0, return "0". Check this corner case, because 0 / -5 will return -0.2. Use long long int for divd and divs, mainly for div... 阅读全文
posted @ 2015-03-19 23:09 keepshuatishuati 阅读(128) 评论(0) 推荐(0) 编辑