LeetCode解题
文章平均质量分 78
leetcode解题
m_buddy
大表哥,还有大招吗... PS:本人所有文章均免费公开,任何收费条目请咨询平台
展开
-
Leetcode——1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the sam原创 2017-02-10 12:01:45 · 425 阅读 · 0 评论 -
Leetcode——27. Remove Element
1. 概述Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant原创 2017-06-01 15:19:26 · 290 阅读 · 0 评论 -
Leetcode——11. Container With Most Water
1. 概述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 endpoints of line i is at (i, ai) and (i原创 2017-06-06 18:00:33 · 331 阅读 · 0 评论 -
Leetcode——17. Letter Combinations of a Phone Number
1. 概述1.1 题目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.原创 2017-06-19 21:14:26 · 354 阅读 · 0 评论 -
Leetcode——19. Remove Nth Node From End of List
1. 概述1.1 题目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 nod原创 2017-06-19 22:03:32 · 281 阅读 · 0 评论 -
Leetcode——20. Valid Parentheses
1. 概述1.1 题目Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "(原创 2017-06-20 10:55:58 · 302 阅读 · 0 评论 -
Leetcode——21. Merge Two Sorted Lists
1. 概述1.1 题目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.1.2 解题思路在这道题中需要将两个排列好的链表组合起来,由于链表中的元素都原创 2017-06-20 11:30:57 · 413 阅读 · 0 评论 -
Leetcode——26. Remove Duplicates from Sorted Array
1. 概述1.1 题目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原创 2017-06-20 15:41:59 · 290 阅读 · 0 评论 -
Leetcode——22. Generate Parentheses
1. 概述1.1 题目Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())",原创 2017-06-20 17:44:13 · 298 阅读 · 0 评论 -
Leetcode——14. Longest Common Prefix
1. 概述Write a function to find the longest common prefix string amongst an array of strings.题目如上,意思就是在给定的一个字符串数组中,求取所有字符串中的最长公共前缀。2. 编码2.1 方法1第一种方法是直接拿一个字符串与其它的字符串相比较,记录本次比较重最长公共前缀,遍历完之后就得到原创 2017-06-01 12:00:53 · 468 阅读 · 0 评论 -
Leetcode——16. 3Sum Closest
1. 概述1.1 题目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原创 2017-06-16 11:27:03 · 474 阅读 · 0 评论 -
Leetcode——2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i原创 2017-02-10 12:49:17 · 315 阅读 · 0 评论 -
Leetcode——6. ZigZag Conversion
1. 概述题目的原文是这样的: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原创 2017-05-27 09:41:50 · 384 阅读 · 0 评论 -
Leetcode——5. Longest Palindromic Substring
1. 概述Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid a原创 2017-05-27 10:22:48 · 313 阅读 · 0 评论 -
Leetcode——69. Sqrt(x)
1. 概述Implement int sqrt(int x).Compute and return the square root of x.由上可知这道题的意思是想用程序自己去实现求取一个数的平方根运算。2. 编码2.1 方法1最简单有效的方法就是调用C++的sqrt()函数,但是这明显有作弊之嫌,出题人的意思也不是这样的。对应的实现的代码也很简单,就原创 2017-05-30 14:55:55 · 616 阅读 · 0 评论 -
Leetcode——4. Median of Two Sorted Arrays
1. 概述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)).Example 1:原创 2017-05-31 21:18:42 · 352 阅读 · 0 评论 -
Leetcode——3. Longest Substring Without Repeating Characters
1. 概述Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the原创 2017-05-31 21:51:17 · 316 阅读 · 0 评论 -
Leetcode——15. 3Sum
1. 概述1.1 题目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: The solution s原创 2017-06-16 11:11:17 · 333 阅读 · 0 评论 -
Leetcode——18.4Sum
1. 概述1.1 题目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.原创 2017-06-16 11:16:57 · 287 阅读 · 0 评论 -
Leetcode——24. Swap Nodes in Pairs
1. 概述1.1 题目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 onl原创 2017-06-20 22:43:28 · 380 阅读 · 0 评论