摘要: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined as a character sequence consists of non-space characters only. For example, Given s = "H 阅读全文
posted @ 2013-09-24 23:36 懒猫欣 阅读(173) 评论(0) 推荐(0)
摘要: Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.记住是向右移。。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) 阅读全文
posted @ 2013-09-24 23:22 懒猫欣 阅读(118) 评论(0) 推荐(0)
摘要: Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,If S = [1,2,3], a solution is:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]注意空集class Solution {publi... 阅读全文
posted @ 2013-09-24 23:00 懒猫欣 阅读(181) 评论(0) 推荐(0)
摘要: Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example,Given[0,1,0,2,1,0,1,3,2,1,2,1], return6.用一个栈辅助,小于等于栈顶的话压入,大于栈顶就把所有小于当前值的元素出栈,计算面积面积也用一个栈,每次把新的面积覆盖范围内的所有的面积出栈,剩下到最后的就是相互独立的了将这些面积加起来,并且减去下面的 阅读全文
posted @ 2013-09-24 22:39 懒猫欣 阅读(187) 评论(0) 推荐(0)
摘要: 转自 http://www.cnblogs.com/goodhacker/archive/2011/07/20/2111996.htmlC风格的强制类型转换(Type Cast)很简单,不管什么类型的转换统统是:TYPE b = (TYPE)a。C++风格的类型转换提供了4种类型转换操作符来应对不同场合的应用。const_cast,字面上理解就是去const属性。static_cast,命名上理解是静态类型转换。如int转换成char。dynamic_cast,命名上理解是动态类型转换。如子类和父类之间的多态类型转换。reinterpret_cast,仅仅重新解释类型,但没有进行二进制的转换。 阅读全文
posted @ 2013-09-24 17:23 懒猫欣 阅读(185) 评论(0) 推荐(0)
摘要: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combination.Note:All numbers (including target) will be positive integers.Elements in a combination (a1, a2, … , 阅读全文
posted @ 2013-09-24 00:44 懒猫欣 阅读(151) 评论(0) 推荐(0)
摘要: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number of times.Note:All numbers (including target) will be positive integers.Elements in a combination (a1, a 阅读全文
posted @ 2013-09-24 00:37 懒猫欣 阅读(179) 评论(0) 推荐(0)