![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode与面试题
文章平均质量分 55
Joyyiwei
这个作者很懒,什么都没留下…
展开
-
LeetCode Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements.Y原创 2014-12-16 17:12:10 · 5509 阅读 · 0 评论 -
LeetCode 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 exact原创 2015-01-27 15:04:57 · 677 阅读 · 0 评论 -
LeetCode 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 input case原创 2015-01-08 23:13:57 · 793 阅读 · 0 评论 -
LeetCode Palindrome Number
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 convertin原创 2015-01-11 23:55:14 · 852 阅读 · 0 评论 -
LeetCode 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 st原创 2015-01-31 20:01:14 · 689 阅读 · 0 评论 -
LeetCode 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 target, whe原创 2014-12-23 00:49:19 · 1065 阅读 · 0 评论 -
LeetCode 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:Element原创 2015-01-30 19:29:07 · 699 阅读 · 0 评论 -
LeetCode 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 O(log (m+n)).Show Tags原创 2014-12-24 01:06:51 · 915 阅读 · 0 评论 -
LeetCode Find Minimum in Rotated Sorted Array II
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot unkno原创 2014-12-08 21:37:51 · 882 阅读 · 0 评论 -
LeetCode Find Peak Element
A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in原创 2014-12-08 21:00:56 · 1287 阅读 · 0 评论 -
LeetCode Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2014-12-08 21:12:22 · 769 阅读 · 0 评论 -
LeetCode 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原创 2015-02-02 10:58:15 · 668 阅读 · 0 评论 -
LeetCode Regular Expression Matching
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st原创 2015-01-14 11:27:28 · 806 阅读 · 0 评论 -
LeetCode Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN原创 2015-02-04 17:11:24 · 684 阅读 · 0 评论 -
LeetCode Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters Total Accepted: 35063 Total Submissions: 159111My SubmissionsQuestion Solution Given a string, find the length of the longest subst原创 2014-12-30 15:34:41 · 785 阅读 · 0 评论 -
LeetCode Container With Most Water
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, 0). Fin原创 2015-01-17 23:01:24 · 762 阅读 · 0 评论 -
Leetcode Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.题意:将阿拉伯数字转换为罗马数字表示思路:首先了解罗马数字的表示,然后就是从大到小找符合的数字了class Solution {public: strin原创 2015-01-19 14:46:47 · 750 阅读 · 0 评论 -
LeetCode 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 va原创 2015-02-08 12:44:41 · 653 阅读 · 0 评论 -
LeetCode Longest Palindromic Substring
Longest Palindromic Substring Question Solution 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原创 2015-01-03 00:45:25 · 1042 阅读 · 0 评论 -
LeetCode 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原创 2015-01-01 17:59:51 · 1016 阅读 · 0 评论 -
LeetCode Generate Parentheses
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:"((()))", "(()())", "(())()", "()(())", "()()原创 2015-02-09 13:41:14 · 616 阅读 · 0 评论 -
LeetCode Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.题意:不用乘除和mod运算计算两个数相除。思路:因为每个数都能表示为二进制,也就是num = a*2^0 + b*2^1....,所以我们只要去判断有哪些2^k就能原创 2015-02-22 16:12:47 · 904 阅读 · 0 评论 -
LeetCode 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原创 2015-02-17 20:47:22 · 644 阅读 · 0 评论 -
LeetCode 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-02-18 19:22:02 · 665 阅读 · 0 评论 -
LeetCode 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原创 2015-02-16 21:12:05 · 656 阅读 · 0 评论 -
LeetCode 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原创 2015-02-19 20:30:14 · 670 阅读 · 0 评论 -
LeetCode 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.题意:将两个有序的链表合并成一个链表思路:每次比较链表头就行了,把比较小的插入新的链表中/**原创 2015-02-10 15:10:14 · 682 阅读 · 0 评论 -
LeetCode Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without原创 2015-02-23 21:07:58 · 742 阅读 · 0 评论 -
LeetCode Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.题意:求字符串数组的最长公共前缀思路:首先找到最短的那个作为标尺,然后每次比较。class Solution {public: string longestCommonPrefix(vector &st原创 2015-01-23 20:26:23 · 809 阅读 · 0 评论 -
LeetCode 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原创 2015-02-25 20:43:07 · 623 阅读 · 0 评论 -
LeetCode 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.原创 2015-02-26 19:25:13 · 624 阅读 · 0 评论 -
LeetCode 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)P A H NA P L S I原创 2015-01-05 19:04:57 · 825 阅读 · 0 评论 -
LeetCode Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.题意:讲罗马数字转换成阿拉伯数字思路:了解罗马数字的构造后,从后往前处理就行了class Solution {public: int romanToInt(s原创 2015-01-23 00:17:18 · 982 阅读 · 0 评论 -
LeetCode Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题意:将k个已经排好序的链表合并成一个思路:用到优先队列比较简单。/** * Definition for singly-linked list. * struct ListNod原创 2015-02-10 16:03:01 · 685 阅读 · 0 评论 -
LeetCode Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Show Tags题意:将数原创 2015-01-07 09:48:50 · 731 阅读 · 0 评论 -
LeetCode 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原创 2015-02-24 20:06:37 · 641 阅读 · 0 评论 -
LeetCode Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",原创 2015-02-27 20:45:12 · 627 阅读 · 0 评论 -
LeetCode Merge Intervals
Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].题意:去掉重复的区间。思路:排序后,再比较end的情况。/** * Definition fo原创 2015-03-14 23:20:50 · 666 阅读 · 0 评论 -
LeetCode Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.题意:有一个数组,只有一个数出现一次,其他的都出现三次,找出一次的数思路:首先我们想到是每次把每一位二进制上1的个数都mod3,然后就能找出一个的了,但是这样空间太大了,所以我们想能记录原创 2015-02-13 21:27:29 · 634 阅读 · 0 评论 -
LeetCode 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. Y原创 2015-02-14 20:56:06 · 644 阅读 · 0 评论