随笔分类 -  LeetCode

上一页 1 ··· 4 5 6 7 8
摘要:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.思考:罗马数字有I,V,X,L,C,D,M。其中4,9左减,其他右加。class Solution {public: string intToRoman(int num) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance... 阅读全文
posted @ 2013-11-08 11:45 七年之后 阅读(190) 评论(0) 推荐(0)
摘要:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpo... 阅读全文
posted @ 2013-11-08 00:52 七年之后 阅读(158) 评论(0) 推荐(0)
摘要:Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.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. Howe 阅读全文
posted @ 2013-11-07 16:24 七年之后 阅读(208) 评论(0) 推荐(0)
摘要: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). You are r 阅读全文
posted @ 2013-11-07 15:54 七年之后 阅读(206) 评论(0) 推荐(0)
摘要:Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!If the integer's last digit is 0, what sho 阅读全文
posted @ 2013-11-07 11:29 七年之后 阅读(166) 评论(0) 推荐(0)
摘要: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 for better legibility)P A H NA P L S I I GY I RAnd then read line by line: "PAHNAPLSIIGYIR"Write the code that will take a string 阅读全文
posted @ 2013-11-07 01:29 七年之后 阅读(230) 评论(0) 推荐(0)
摘要:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longes... 阅读全文
posted @ 2013-11-06 18:24 七年之后 阅读(246) 评论(0) 推荐(0)
摘要: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 digit. Add the two numbers and return it as a linked list.Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8注意点:改了又改,好多测试用例没有考 阅读全文
posted @ 2013-11-06 11:55 七年之后 阅读(249) 评论(0) 推荐(0)
摘要:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo... 阅读全文
posted @ 2013-11-05 21:18 七年之后 阅读(190) 评论(0) 推荐(0)
摘要: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 O(log (m+n)).思考:既然是有序数组,自然想到折半搜索。每次比较去掉其中一个数组一半的数字。class Solution {public: int func(int *A,int m,int *B,int n,int k) { if(m>n) return func(B,n,A,m, 阅读全文
posted @ 2013-11-05 21:12 七年之后 阅读(165) 评论(0) 推荐(0)
摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu... 阅读全文
posted @ 2013-11-05 15:11 七年之后 阅读(270) 评论(0) 推荐(0)

上一页 1 ··· 4 5 6 7 8