04 2015 档案
[LeetCode] #21 Merge Two Sorted Lists
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.本题就是简单的链表... 阅读全文
posted @ 2015-04-24 09:49 NealCaffrey989 阅读(150) 评论(0) 推荐(0)
[LeetCode] #20 Valid Parentheses
摘要:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ... 阅读全文
posted @ 2015-04-23 20:43 NealCaffrey989 阅读(135) 评论(0) 推荐(0)
[LeetCode] #19 Remove Nth Node From End of List
摘要: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... 阅读全文
posted @ 2015-04-23 16:23 NealCaffrey989 阅读(159) 评论(0) 推荐(0)
[LeetCode] #18 4Sum
摘要: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 ... 阅读全文
posted @ 2015-04-22 22:07 NealCaffrey989 阅读(121) 评论(0) 推荐(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 telephon... 阅读全文
posted @ 2015-04-21 14:58 NealCaffrey989 阅读(208) 评论(0) 推荐(0)
[LeetCode] #16 3Sum Closest
摘要: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 m... 阅读全文
posted @ 2015-04-21 14:56 NealCaffrey989 阅读(187) 评论(0) 推荐(0)
编程之美2015 #1 2月29日
摘要:题目:时间限制:2000ms单点时限:1000ms内存限制:256MB描述给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期)。只有闰年有2月29日,满足以下一个条件的年份为闰年:1. 年份能被4整除但不能被100整除2. 年份能被400整除输入第一行为一个整数T,表示数据组数。之后每... 阅读全文
posted @ 2015-04-20 22:33 NealCaffrey989 阅读(178) 评论(0) 推荐(0)
编程之美2015 #2 回文字符序列
摘要:题目:时间限制:2000ms单点时限:1000ms内存限制:256MB描述给定字符串,求它的回文子序列个数。回文子序列反转字符顺序后仍然与原序列相同。例如字符串aba中,回文子序列为"a", "a", "aa", "b", "aba",共5个。内容相同位置不同的子序列算不同的子序列。输入第一行一个整... 阅读全文
posted @ 2015-04-20 22:26 NealCaffrey989 阅读(216) 评论(0) 推荐(0)
编程之美2015 #3 基站选址
摘要:题目:时间限制:2000ms单点时限:1000ms内存限制:256MB描述需要在一个N × M的网格中建立一个通讯基站,通讯基站仅必须建立在格点上。网格中有A个用户,每个用户的通讯代价是用户到基站欧几里得距离的平方。网格中还有B个通讯公司,维护基站的代价是基站到最近的一个通讯公司的路程(路程定义为曼... 阅读全文
posted @ 2015-04-20 22:25 NealCaffrey989 阅读(230) 评论(0) 推荐(0)
[LeetCode] #15 3Sum
摘要: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:Elemen... 阅读全文
posted @ 2015-04-19 22:31 NealCaffrey989 阅读(201) 评论(0) 推荐(0)
[LeetCode] #14 Longest Common Prefix
摘要:Write a function to find the longest common prefix string amongst an array of strings.本题寻找一组字符串的公共前缀,只需要查询较短子串前n个字符是否相等。时间:8ms代码如下:class Solution {pub... 阅读全文
posted @ 2015-04-19 22:30 NealCaffrey989 阅读(119) 评论(0) 推荐(0)
[LeetCode] #13 Roman to Integer
摘要:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.简单的字符转化,将读取的字符每一位转化为对应数字,再计算。时间:58ms代码如下:cla... 阅读全文
posted @ 2015-04-16 22:46 NealCaffrey989 阅读(133) 评论(0) 推荐(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.将不同罗马字符和对应的数字做成字典,然后将依次转化。时间:55ms代码如下:class ... 阅读全文
posted @ 2015-04-16 22:45 NealCaffrey989 阅读(113) 评论(0) 推荐(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 ... 阅读全文
posted @ 2015-04-16 22:44 NealCaffrey989 阅读(101) 评论(0) 推荐(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... 阅读全文
posted @ 2015-04-11 20:07 NealCaffrey989 阅读(114) 评论(0) 推荐(0)
[LeetCode] #9 Palindrome Number
摘要:Determine whether an integer is a palindrome. Do this without extra space.看到题目第一想法是将数字倒过来相减,看是否为0,但是会超时。原因是大部分可能并不是,所以循环中间就退出循环了。目前这个程序是按最左位与最右位逐次比较。时... 阅读全文
posted @ 2015-04-11 19:58 NealCaffrey989 阅读(94) 评论(0) 推荐(0)
[LeetCode] #8 String to Integer (atoi)
摘要:Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ... 阅读全文
posted @ 2015-04-10 10:09 NealCaffrey989 阅读(113) 评论(0) 推荐(0)
[LeetCode] #7 Reverse Integer
摘要:Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321题目很简单,先判断数字的正负,再按位倒置数字就可以了。不过要考虑int的上限。时间:16ms代码如下:class Soluti... 阅读全文
posted @ 2015-04-09 21:42 NealCaffrey989 阅读(95) 评论(0) 推荐(0)
[LeetCode] #6 ZigZag Conversion
摘要:The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font fo... 阅读全文
posted @ 2015-04-08 11:34 NealCaffrey989 阅读(110) 评论(0) 推荐(0)
[LeetCode] #5 Longest Palindromic Substring
摘要:Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest pa... 阅读全文
posted @ 2015-04-07 20:32 NealCaffrey989 阅读(119) 评论(0) 推荐(0)
[LeetCode] #4 Median of Two Sorted Arrays
摘要:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be ... 阅读全文
posted @ 2015-04-06 19:23 NealCaffrey989 阅读(141) 评论(0) 推荐(0)
[LeetCode] #3 Longest Substring Without Repeating Characters
摘要:今天清明,再补一篇Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating l... 阅读全文
posted @ 2015-04-05 21:21 NealCaffrey989 阅读(136) 评论(0) 推荐(0)
[LeetCode] #2 Add Two Numbers
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single ... 阅读全文
posted @ 2015-04-05 18:22 NealCaffrey989 阅读(120) 评论(0) 推荐(0)
[LeetCode] #1 Two Sum
摘要:今天开始,每天一道LeetCode!Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return ind... 阅读全文
posted @ 2015-04-04 15:49 NealCaffrey989 阅读(178) 评论(0) 推荐(0)