![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 85
inlcude_cx
这个作者很懒,什么都没留下…
展开
-
LeetCode 12 Integer to Roman(C,C++,Java,Python)
Problem:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.Solution:根据数字将每一位转换为罗马字符串即可,时间复杂度O(len(num))题目大意:给一个整数,将整数调整为罗马数字,原创 2015-05-08 13:13:53 · 1803 阅读 · 0 评论 -
LeetCode 3 Longest Substring Without Repeating Characters
Problem: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 lengt原创 2015-05-05 20:20:38 · 594 阅读 · 0 评论 -
LeetCode 4 Median of Two Sorted Arrays
Problem: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)).Solution:使用原创 2015-05-06 11:10:30 · 1361 阅读 · 0 评论 -
LeetCode 5 Longest Palindromic Substring(C,C++,Python,Java)
Problem: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.Soluti原创 2015-05-06 15:38:22 · 2062 阅读 · 0 评论 -
LeetCode 31 Next Permutation (C,C++,Java,Python)
Problem: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 l原创 2015-05-14 14:36:42 · 2105 阅读 · 0 评论 -
LeetCode 6 ZigZag Conversion (C,C++,Java,Python)
Problem: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原创 2015-05-06 22:55:25 · 1543 阅读 · 0 评论 -
LeetCode 30 Substring with Concatenation of All Words (C,C++,Java,Python)
Problem: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 wordsexac原创 2015-05-14 13:13:52 · 2119 阅读 · 0 评论 -
LeetCode 33 Search in Rotated Sorted Array (C,C++,Java,Python)
Problem: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 t原创 2015-05-14 19:59:49 · 707 阅读 · 0 评论 -
LeetCode 34 Search for a Range (C,C++,Java,Python)
Problem: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原创 2015-05-14 21:28:11 · 1890 阅读 · 0 评论 -
LeetCode 32 Longest Valid Parentheses (C,C++,Java,Python)
Problem:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substri原创 2015-05-14 17:16:32 · 1244 阅读 · 0 评论 -
LeetCode 7 Reverse Integer(C,C++,Java,Python)
Problem:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus原创 2015-05-07 09:23:20 · 1324 阅读 · 0 评论 -
LeetCode 9 Palindrome Number
Problem: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 thinkin原创 2015-05-07 11:21:40 · 615 阅读 · 0 评论 -
LeetCode 8 String to Integer (atoi) (C,C++,Java,Python)
Problem: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 pos原创 2015-05-07 10:38:53 · 3055 阅读 · 0 评论 -
LeetCode 10 Regular Expression Matching (C,C++,Java,Python)
Problem: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 e原创 2015-05-07 21:02:00 · 1604 阅读 · 0 评论 -
LeetCode 11 Container With Most Water (C,C++,Java,Python)
Problem: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原创 2015-05-07 22:56:04 · 1801 阅读 · 0 评论 -
LeetCode 35 Search Insert Position (C,C++,Java,Python)
Problem: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原创 2015-05-18 20:33:01 · 1717 阅读 · 0 评论 -
LeetCode 36 Valid Sudoku (C,C++,Java,Python)
Problem: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 p原创 2015-05-18 22:56:46 · 3880 阅读 · 0 评论 -
LeetCode 38 Count and Say(C,C++,Java,Python)
Problem: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 i原创 2015-05-19 21:36:24 · 3514 阅读 · 0 评论 -
LeetCode 1 Two Sum 题解
Problem: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原创 2015-05-05 16:53:05 · 1827 阅读 · 0 评论 -
LeetCode 29 Divide Two Integers (C,C++,Java,Python)
Problem:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.Solution:不能乘除就加减就行了,但是一个问题是加减有可能速度太慢,因此需要转换,由于任何一个数都能表示成二进制,所以有d原创 2015-05-13 09:27:20 · 2972 阅读 · 1 评论 -
LeetCode 13 Roman to Integer (C,C++,Java,Python)
Problem:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Solution:时间复杂度O(n)题目大意:与12题相反,给一个罗马数字,要求转化为十进制数字解题思路:Java源原创 2015-05-08 16:57:01 · 1313 阅读 · 0 评论 -
LeetCode 14 Longest Common Prefix (C,C++,Java,Python)
Problem:Write a function to find the longest common prefix string amongst an array of strings.Solution:时间复杂度O(n)题目大意:给一个字符串数组,要找到这些字符串的最大前缀公共子串。解题思路:既然是公共子串,那每个字符串肯定都包含有,并且在头部,首先把第原创 2015-05-08 18:40:35 · 5892 阅读 · 2 评论 -
LeetCode 15 3Sum (C,C++,Java,Python)
Problem: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原创 2015-05-09 21:06:57 · 5681 阅读 · 0 评论 -
LeetCode 16 3Sum Closest(C,C++,Java,Python)
Problem: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 woul原创 2015-05-09 22:26:02 · 2597 阅读 · 0 评论 -
LeetCode 20 Valid Parentheses (C,C++,Java,Python)
Problem:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}原创 2015-05-10 16:41:00 · 4201 阅读 · 0 评论 -
LeetCode 21 Merge Two Sorted Lists (C,C++,Java,Python)
Problem: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.Solution:两个有序链表,每次取头部最小的那个元素,然后将这个元素从原来链表原创 2015-05-10 17:15:00 · 1771 阅读 · 1 评论 -
LeetCode 18 4Sum (C,C++,Java,Python)
Problem: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原创 2015-05-10 15:04:02 · 2494 阅读 · 0 评论 -
LeetCode 19 Remove Nth Node From End of List (C,C++,Java,Python)
Problem: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 fro原创 2015-05-10 16:07:27 · 1259 阅读 · 0 评论 -
LeetCode 17 Letter Combinations of a Phone Number(C,C++,Java,Python)
Problem: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.原创 2015-05-10 13:39:32 · 3824 阅读 · 0 评论 -
LeetCode 22 Generate Parentheses (C,C++,Java,Python)
Problem: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-05-10 21:11:15 · 2251 阅读 · 0 评论 -
LeetCode 23 Merge k Sorted Lists (C,C++,Java,Python)
Problem:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Solution:采用胜者树的方法,胜者树介绍:胜者树,假如链表数组长度为n,链表元素总个数为k,那么时间复杂度为O(k*log(n))题目大意:原创 2015-05-11 15:39:00 · 1461 阅读 · 0 评论 -
LeetCode 24 Swap Nodes in Pairs (C,C++,Java,Python)
Problem: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 con原创 2015-05-11 16:37:22 · 2227 阅读 · 1 评论 -
LeetCode 25 Reverse Nodes in k-Group (C,C++,Java,Python)
Problem: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 r原创 2015-05-11 19:55:08 · 1524 阅读 · 0 评论 -
LeetCode 26 Remove Duplicates from Sorted Array (C,C++,Java,Python)
Problem: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原创 2015-05-11 20:25:19 · 1118 阅读 · 0 评论 -
LeetCode 27 Remove Element (C,C++,Java,Python)
Problem: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 ne原创 2015-05-11 20:40:46 · 1964 阅读 · 0 评论 -
LeetCode 28 Implement strStr() (C,C++,Java,Python)
Problem: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 ha原创 2015-05-12 11:59:17 · 2426 阅读 · 0 评论 -
LeetCode 2 Add Two Numbers
Problem: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 retur原创 2015-05-05 18:25:05 · 868 阅读 · 1 评论 -
LeetCode 37 Sudoku Solver (C,C++,Java,Python)
Problem:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.原创 2015-05-19 13:11:05 · 2920 阅读 · 0 评论