
LeetCode & LintCode
文章平均质量分 62
逆風的薔薇
这个作者很懒,什么都没留下…
展开
-
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原创 2015-04-27 16:57:18 · 4481 阅读 · 0 评论 -
LeetCode(9)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 s原创 2015-04-28 21:31:19 · 873 阅读 · 0 评论 -
LeetCode(1)Two Sum
题目: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 numbers such that they add up to the ta原创 2015-04-28 08:34:23 · 966 阅读 · 1 评论 -
LeetCode(7)Reverse Integer
题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321分析:乍看,好似是一个很简单的题目,只需要将整数从最低位起到最高位依次处理即可,但是,此题的关键在于如何处理溢出数据。我们知道,Integer类型数据的范围是:#define原创 2015-04-27 15:36:05 · 857 阅读 · 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 letters for "abcabcbb" is "abc", which the length is原创 2015-05-13 17:08:30 · 871 阅读 · 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 digit. Add the two numbers and return it原创 2015-04-23 20:48:51 · 1035 阅读 · 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”原创 2015-08-07 21:07:51 · 920 阅读 · 0 评论 -
LeetCode(16)3Sum Closest
题目Given an array S of n integers, find three integers in S such 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 exactl原创 2015-08-07 17:29:56 · 1038 阅读 · 0 评论 -
LeetCode(15) 3Sum
题目Given an array S of n integers, are there elements a, b, c in S such that a + 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原创 2015-08-06 16:40:30 · 1066 阅读 · 0 评论 -
LeetCode(19) Remove Nth Node From End of List
题目Given a linked list, remove the nth node 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原创 2015-08-08 16:38:49 · 702 阅读 · 0 评论 -
LeetCode(4)Median of Two Sorted Arrays
题目There are two sorted arrays nums1 and nums2 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)).分析给定两个有序序列,要求两个序列综合后的中位数。关键:原创 2015-08-22 20:35:01 · 1876 阅读 · 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 order, “()” and “()[]{}” are all valid but原创 2015-08-09 16:43:00 · 686 阅读 · 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 for better legibility) And then read line by l原创 2015-08-23 17:29:34 · 678 阅读 · 0 评论 -
LeetCode(29)Divide Two Integers
题目Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.分析题目要求不用 * / %三种运算符的条件下,求得两个int类型整数的商。方法一:很明显的,我们可以用求和累计的方法,求得商,但是该方法测试会出现TLE;参考博客提出解决办法:原创 2015-08-24 19:51:50 · 689 阅读 · 0 评论 -
LeetCode(30) Substring with Concatenation of All Words
题目You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and w原创 2015-08-24 20:51:05 · 3103 阅读 · 0 评论 -
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.分析数据结构与算法的链表章节的典型实例,将两个有序链表合成一个,保持其有序的性质。AC代码/** * Defini原创 2015-08-10 16:23:33 · 773 阅读 · 0 评论 -
LeetCode(24) Swap Nodes in Pairs
题目Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may原创 2015-08-10 19:24:07 · 661 阅读 · 0 评论 -
LeetCode(25)Reverse Nodes in k-Group
题目Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.Yo原创 2015-08-10 20:16:51 · 717 阅读 · 0 评论 -
LeetCode(33)Search in Rotated Sorted Array
题目Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its ind原创 2015-08-25 17:25:01 · 762 阅读 · 1 评论 -
LeetCode(26) Remove Duplicates from Sorted Array
题目Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with co原创 2015-08-10 20:54:32 · 604 阅读 · 0 评论 -
LeetCode(41)First Missing Positive
题目Given an unsorted integer array, find the first missing positive integer.For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant space.原创 2015-08-26 17:31:12 · 789 阅读 · 0 评论 -
LeetCode(36)Valid Sudoku
题目Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’. A partially filled sudoku wh原创 2015-08-25 20:40:50 · 3252 阅读 · 0 评论 -
LeetCode(27)Remove Element
题目Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn’t matter what you leave beyond the new length.分析这是一道很简原创 2015-08-12 16:50:06 · 2238 阅读 · 0 评论 -
LeetCode(28)Implement strStr()
题目Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02): The signature of the function had been updated to ret原创 2015-08-12 17:36:36 · 718 阅读 · 0 评论 -
LeetCode(38) Count and Say
题目The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “one 2, t原创 2015-08-26 11:14:38 · 4551 阅读 · 0 评论 -
LeetCode(31) Next Permutation
题目Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible or原创 2015-08-13 16:12:05 · 2267 阅读 · 0 评论 -
LeetCode(171) Excel Sheet Column Number
题目Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C -> 3...Z -> 26AA -> 27AB -> 28 ..原创 2015-08-13 21:38:16 · 933 阅读 · 0 评论 -
LeetCode(43)Multiply Strings
题目Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.分析计算两个字符串表示的非负大整数的乘积,结果仍然用字符串表示。我们都熟悉笔算的整数乘积原创 2015-08-28 17:42:02 · 4237 阅读 · 0 评论 -
LeetCode(169)Majority Element
题目Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element alway原创 2015-08-15 20:47:19 · 604 阅读 · 0 评论 -
LeetCode(237)Delete Node in a Linked List
题目Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3,原创 2015-08-15 21:32:23 · 1444 阅读 · 0 评论 -
LeetCode(46)Permutations
题目Given a collection of numbers, return all possible permutations.For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].分析求给定向量数组所有元素的全排列问题。我们原创 2015-08-31 20:07:48 · 2513 阅读 · 0 评论 -
LeetCode(47)Permutations II
题目Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], and [2,1,1].分析用上一原创 2015-08-31 20:15:49 · 503 阅读 · 0 评论 -
LeetCode(48)Rotate Image
题目You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up: Could you do this in-place?分析本地使得二维矩阵,旋转90角度。通过实际数据分析,通过两个步骤的元素交换可实现目标:按照主对角线,将对称元素交换按照原创 2015-08-31 20:49:30 · 2801 阅读 · 0 评论 -
LeetCode(59)Length of Last Word
题目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原创 2015-08-15 21:08:47 · 569 阅读 · 0 评论 -
LeetCode(34)Search for a Range
题目Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If the target is not found in the原创 2015-08-17 16:03:43 · 922 阅读 · 0 评论 -
LeetCode(35) Search Insert Position
题目Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Her原创 2015-08-17 16:28:53 · 912 阅读 · 0 评论 -
LeetCode(49)Group Anagrams
题目Given an array of strings, group anagrams together.For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return:[ [“ate”, “eat”,”tea”], [“nat”,”tan”], [“bat”] ] Note: For the原创 2015-09-01 20:28:44 · 7202 阅读 · 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~3999之间的整型数字转换为罗马数字并输出。 解这道题我们必须了解罗马字母与整数之间的对应: 对照举例如下: AC代码class Solution原创 2015-08-05 21:03:53 · 1068 阅读 · 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.分析这个题目是上一题的变形,要求将给定的罗马序列数字转换为对应的整数。 了解罗马数字与整数的对应关系: 对应举例如下: AC代码class Solution{public原创 2015-08-05 21:15:02 · 941 阅读 · 0 评论 -
LeetCode(61) Rotate List
题目Given a list, rotate the list to the right by k k places, where kk is non-negative.For example: Given 1−>2−>3−>4−>5−>NULL1->2->3->4->5->NULL andk=2 k = 2, return 4−>5−>1−>2−>3−>NULL4->5->1->2->3->原创 2015-09-07 20:45:44 · 633 阅读 · 0 评论