ITeye博客

vvaaiinn的博客

vvaaiinn · 共 29 篇文章

LeetCode 19 Remove Nth Node From End of List 移除倒数第N个节点

题目: Given a linked list, remove thenthnode from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Note: Givennwill always be valid. Try to do this in one pass. 翻译: 给你一个链表,移除…

2015-05-04 15:37 · 评论(0)

LeetCode 18 4sum 找出4个数,使得他们的和等于target

题目 : Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of target. Note: Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie,a≤b≤c≤d) The solution set must not contain duplicate quadr…

2015-05-04 15:05 · 评论(0)

Java List ArrayList用法详解

转自:http://blog.csdn.net/hutuchongaini/article/details/12945401 刚才刷LeetCode的碰到的一个小细节的问题,就是List的声明问题。 找了一个写的比较不错的文章,转之,学习之。 List是一个接口,而ListArray是一个类。 ListArray继承并实现了List。 所以List不能被构造,但可以向上面那样为List创建一个引用,而ListArray就可以被构造。 List list; //正确 list=null; List list=new List(); // 是错误的用法 List list = new Array…

2015-05-04 11:09 · 评论(0)

LeetCode 17 Letter Combinations of a Phone Number 数字转为字母组合

题目: Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string "23" Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]. Note: Although the above answ…

2015-05-04 10:38 · 评论(0)

LeetCode 16 3Sum Closest 找出最接近指定target的三个数的和

题目: Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For example, given array S = {-1 2 1 -4}, and target = 1. The sum that is closest to t…

2015-05-04 09:26 · 评论(0)

安卓解析xml格式字符串

最近实验室的安卓app需要实现发内部邮件的功能。 说白了就是简单的数据库的增删处理。 但是中间的一部分有意思的就是获取收件人的列表的处理。 用户在登录APP的时候,如果验证成功,服务器则把数据的联系人的所有信息发送回来到客户端。 发送出来的格式是dataset,处理之后转换为xml格式的字符串发出来。 当发邮件的时候 ,则会在收件人提供一个Spinner控件,然后把所有人的名字显示出来。 这个时候就涉及到xml格式的字符串的解析。 我的实现方法很简单。用的是PULL方法。希望能够帮助到需要的同学。 首先看服务器端发回的字符串格式 <span style="font-size:18px;"><…

2015-04-30 14:03 · 评论(0)

LeetCode 15 3Sum 找出数组里面3个数的和等于指定值。

题目:Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must be in non-descending order. (ie,a≤b≤c) The solution set must not contain duplicate triplets. For example, given arr…

2015-04-23 13:17 · 评论(0)

LeetCode 14 Longest Common Prefix 最长前缀

题目:Write a function to find the longest common prefix string amongst an array of strings. 翻译:求一个字符串数组中 共同的最长前缀。 思路:以第一个串为基准,逐个位置遍历,并遍历字符串数组,如果出现某个字符串长度小于当前位置,或者出现当前位置的字符不相同,返回字串strs[0].substring(0,pos);思路很简单。 代码: public String longestCommonPrefix(String[] strs) { int count = strs.length;//字符串的个数 in…

2015-04-23 09:33 · 评论(0)

LeetCode13 Roman to Integer 罗马转为数字

题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 翻译:把罗马转为数字 思路:如果是单纯的一个罗马字母比较好处理,但是对于4,9这样的,应该看它下一个字符代表的数字是不是比他大,要是大的话减去当前的字符代表的数字。要是小的话,则加上这个数字。 像IV ,代表4.当读到I的时候,应该判断下一个字符V和I的关系,V比I代表的数字大,所以此时应该加上V - I的值,然后指针跳过2. 代码1: public static int…

2015-04-22 13:55 · 评论(0)

Leetcode 12 Integer to Roman整数变罗马

题目: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 翻译: 给一个整数,把他转换为罗马数字输出。 这道题是简单的字符转换的问题。只要了解罗马数字代表的含义即可。 罗马数字里面只有 1,5,10. 1到3之间用重复的1表示,4用IV 90用XC 依次类推。 I = 1; V = 5; X = 10; L = 50; C = 100; D = 500; M = 1000; 代码: public static String in…

2015-04-22 12:56 · 评论(0)

LeetCode 11 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…

2015-04-22 11:11 · 评论(0)

从头到尾彻底理解KMP(2014年8月22日版)

从头到尾彻底理解KMP 转自:http://blog.csdn.net/v_july_v/article/details/7041827 感觉写的不错,看起来可以看懂 作者:July 时间:最初写于2011年12月,2014年7月21日晚10点 全部删除重写成此文,随后的半个多月不断反复改进。 1. 引言 本KMP原文最初写于2年多前的2011年12月,因当时初次接触KMP,思路混乱导致写也写得混乱。所以一直想找机会重新写下KMP,但苦于一直以来对KMP的理解始终不够,故才迟迟没有修改本文。 然近期因在北京开了个算法班,专门讲解数据结构、面试、算法,才再次仔细回顾了这个KMP,在综合了一些网…

2015-04-21 19:58 · 评论(0)

LeetCode 10 Regular Expression Matching 正则匹配

题目: Implement regular expression matching with support for '.' and '*' . '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be: bool isMatch(const char *s, const char *p)…

2015-04-21 19:08 · 评论(0)

LeetCode 9 Palindrome Number 回文数字

题目:Determine whether an integer is a palindrome. Do this without extra space. 翻译:判断一个数字是否是回文数,不要额外空间。 解题思路:因为数字既然传过去了,就不会有越界的问题。每次只需要取最前面和最后面的那一位数字进行比较,相同则继续,不同则返回、 首先要获取数字的位数,假设数字是12344321,一共有8位。 其次是要每次取前后各一位来进行比较,用数字除以1后面7个0得到第一位,用数字对10取余数得到最后一位。 此时要比较第二位和倒数第二位,只需将数字对1后面7个0取余后,在除以10.这样数字就变为234432…

2015-04-20 14:55 · 评论(0)

LeetCode 8 String to Integer (atoi)

题目: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem to be specified vaguely (ie, no given input specs). Yo…

2015-04-20 12:55 · 评论(0)