![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
文章平均质量分 56
你的涛哥哥
这个作者很懒,什么都没留下…
展开
-
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 as a link原创 2016-03-18 09:49:14 · 184 阅读 · 0 评论 -
leetcode-14 Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings求多个字符串的最长公共前缀。1.纵向扫描,从位置0 开始,对每一个位置比较所有字符串,直到遇到一个不匹配。2.横向扫描,每个字符串与第0 个字符串,从左到右比较,直到遇到一个不匹配。////原创 2016-03-25 16:43:33 · 154 阅读 · 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.For example, given array S = {-1 0 1 2 -1 -4}.原创 2016-03-25 16:44:01 · 171 阅读 · 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 exactly原创 2016-03-25 16:44:28 · 176 阅读 · 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 strin原创 2016-03-25 16:45:01 · 220 阅读 · 0 评论 -
leetcode-18 4Sum
Given an array S of n integers, are there elements a; b; c, and d in S such that a+b+c+d = target?Find all unique quadruplets in the array which gives the sum of target.Note:• Elements in a quad原创 2016-03-25 16:46:39 · 195 阅读 · 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 l原创 2016-03-25 16:47:12 · 192 阅读 · 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原创 2016-03-25 16:47:50 · 186 阅读 · 0 评论 -
leetcode-21 Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. e new list should be made by splicing together the nodes of the first two lists.////////////////////////////////////////////////////原创 2016-03-25 16:48:15 · 242 阅读 · 0 评论 -
leetcode-22 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.可以复用两个链表合并,每次合并两个,时间O(n1+n2+...),空间复杂度O(1)////////////////////////////////////////////原创 2016-03-25 16:48:47 · 242 阅读 · 0 评论 -
leetcode-23 Insertion Sort List
Sort a linked list using insertion sort.//////////////////////////////////////////////////////////////////////////// start: Sort list using insert sortListNode *findInsertPos(ListNode原创 2016-03-25 16:49:08 · 234 阅读 · 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.//////////////////////////////////////////////////////////////////////////// start原创 2016-03-25 16:43:01 · 202 阅读 · 0 评论 -
leetcode-11 Container With Most Water
Given n non-negative integers a1; a2; ...; an, where each represents a point at coordinate (i; ai). nvertical lines are drawn such that the two endpoints of line i is at (i; ai) and (i; 0). Find two转载 2016-03-25 16:31:45 · 258 阅读 · 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.罗马数字的基本符号有I(表示十进制数1),V(表示5),X(表示10),L(表示50),C(表示100),D(表示500),M(表示1000)。1、相同的数字列表示原创 2016-03-25 16:31:06 · 271 阅读 · 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)).1.常规方法:合并两个数组,排序,找到原创 2016-03-25 15:36:08 · 248 阅读 · 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 3. Fo原创 2016-03-25 11:13:26 · 191 阅读 · 0 评论 -
leetcode-1 TwoSum
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 target, whe原创 2016-03-18 09:35:51 · 258 阅读 · 0 评论 -
leetcode-5 Longest Palindromic Substring(回文子序列)
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 longest palindromic substring.1.简单解法:暴力枚举遍原创 2016-03-25 16:13:49 · 231 阅读 · 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)http://blog.csdn.net/zho原创 2016-03-25 16:22:19 · 222 阅读 · 0 评论 -
leetcode-7 Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321注意两个问题:1.倒过来的数是否会越界(可以先化为long long型做);2.负数取余和取整的操作,最好先化为正数。////////////////////////////原创 2016-03-25 16:28:21 · 192 阅读 · 0 评论 -
leetcode-8 String to Integer
注意两个问题:1.空格、\t、\n等符号、正负号以及它们出现的位置;如:不规则输入,但是有效,”-3924x8fc”,” +1" (第一个有效字符是正负号或者是数字或者空格,不是则视为无效,到第一个非数字的字符之前为止)无效格式,” ++c”, ” ++1”,+ 413”,“abc”(正负号之后必须是数字,否则无效)2.是否越界,若越界取最大值或最小值。溢出原创 2016-03-25 16:29:21 · 201 阅读 · 0 评论 -
leetcode-9 Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.http://blog.csdn.net/hcbbt/article/details/440012291.可以先转为字符串,再判断。2.直接算出回文的数再直接比较。 // 发现问题:回文数会出现溢出情况,所以取int高一个量级原创 2016-03-25 16:29:58 · 187 阅读 · 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(前面的数字可以出现任意次,包括0次) element.Some examples:isMatch(原创 2016-03-25 16:30:33 · 287 阅读 · 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 ma原创 2016-03-25 16:49:28 · 234 阅读 · 0 评论