2013年10月10日

Longest Common Prefix

摘要: Write a function to find the longest common prefix string amongst an array of strings.思路:先求前两个字符串的公共前缀,然后拿这个前缀和其他字符串进行比对。 1 int min(int a, int b){ 2 if(a &strs) { 7 // Note: The Solution object is instantiated only once and is reused by each test case. 8 int n = strs.siz... 阅读全文

posted @ 2013-10-10 20:29 waruzhi 阅读(169) 评论(0) 推荐(0) 编辑

Palindrome Number

摘要: Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, note the restriction of using extra space.You could also try reversing an integer. However, if you have solved 阅读全文

posted @ 2013-10-10 19:20 waruzhi 阅读(132) 评论(0) 推荐(0) 编辑

Container With Most Water

摘要: Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.Note: You 阅读全文

posted @ 2013-10-10 18:47 waruzhi 阅读(176) 评论(0) 推荐(0) 编辑

Single Number II

摘要: Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?思路是用一个32位的数result的每一位记录所有数在这一位出现的次数,如果是3的倍数则消去,最后留下来的数则是所要的结果。注意,result需要定义为unsigned int类型,否 阅读全文

posted @ 2013-10-10 18:22 waruzhi 阅读(266) 评论(0) 推荐(0) 编辑

Single Number

摘要: Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?进行一次扫描,把所有数据异或在一起,最终结果就是所求结果。1 int singleNumber(int A[], int n) {2 // Note: The Soluti... 阅读全文

posted @ 2013-10-10 17:55 waruzhi 阅读(133) 评论(0) 推荐(0) 编辑

导航