Reverse a singly linked list.参考http://www.2cto.com/kf/201110/106607.html方法1:讲每个节点的指针指向前面就可以。/** * Definition for singly-linked list. * struct ListNode... Read More
posted @ 2015-06-09 21:48 sunalive Views(149) Comments(0) Diggs(0)
Related to questionExcel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A ... Read More
posted @ 2015-06-03 19:29 sunalive Views(128) Comments(0) Diggs(0)
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 ->... Read More
posted @ 2015-06-03 19:28 sunalive Views(123) Comments(0) Diggs(0)
(1)传统的字符串匹配算法:注意这道题中各种特殊情况的返回值。传统字符串匹配就是让目标字符串从第一个字母开始逐个匹配源字符串的每一个字符,直到匹配完全。class Solution {public: int strStr(string haystack, string needle) { ... Read More
posted @ 2015-06-01 16:12 sunalive Views(134) Comments(0) Diggs(0)
Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word doe... Read More
posted @ 2015-05-21 22:07 sunalive Views(103) Comments(0) Diggs(0)
class Solution {public: string longestCommonPrefix(vector& strs) { int len = strs.size(); if(len == 0) return ""; string prefix = strs[0]; for(... Read More
posted @ 2015-05-18 21:17 sunalive Views(111) Comments(0) Diggs(0)
class Solution {public: string calcuate(string s) { string result; char pre = s[0]; int cnt = 1; for(int i =1;i < s.... Read More
posted @ 2015-05-07 10:03 sunalive Views(179) Comments(0) Diggs(0)
class Solution {public: string addBinary(string a, string b) { int car = 0; int cur_a = a.length()-1; int cur_b = b.length()-1... Read More
posted @ 2015-05-06 22:16 sunalive Views(137) Comments(0) Diggs(0)
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.这道题就是将罗马数字转化为一个整数,一开始做的时候很不理解,后来参考了http://bl... Read More
posted @ 2015-05-06 21:04 sunalive Views(123) Comments(0) Diggs(0)
Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is great... Read More
posted @ 2015-05-05 11:00 sunalive Views(151) Comments(0) Diggs(0)