LeetCode刷题记
LeetCode刷题记录
Jung_zhang
这个作者很懒,什么都没留下…
展开
-
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原创 2016-04-21 19:08:23 · 1714 阅读 · 0 评论 -
LeetCode之23---Merge k Sorted Lists
题目: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目大意: 给定k条有序链表,求k条链表有序合并后的链表。思路: 看到这道题感觉蛮亲切的,因为已经不止一次遇到链表有序合并的问题了,所以思路还是有的。 第一原创 2016-04-20 23:43:45 · 787 阅读 · 0 评论 -
LeetCode之22----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:"((()))", "(()())", "(())()", "()(()原创 2016-04-20 19:57:17 · 1140 阅读 · 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.题目大意: 给定两个有序的链表,求有序合并后的链表。思路: 链表有序合并也是原创 2016-04-17 16:59:54 · 3336 阅读 · 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原创 2016-04-16 22:47:36 · 987 阅读 · 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 e原创 2016-04-16 14:33:12 · 3183 阅读 · 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:原创 2016-04-16 00:00:20 · 1075 阅读 · 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原创 2016-04-14 18:46:32 · 3352 阅读 · 0 评论 -
LeetCode之16----3Sums 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 hav原创 2016-04-12 19:14:02 · 1144 阅读 · 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 tripl原创 2016-04-11 22:00:13 · 840 阅读 · 0 评论 -
LeetCode之14---Longest Common Prefix
题目: Write a function to find the longest common prefix string amongst an array of strings.题目大意: 写一个函数,求一个字符串数组中最长的公共前缀子串。思路: 在做这道题之前先要了解一下什么叫做公共前缀子串。在英语中一个单词可以分为前缀、词根、后缀三部分,所谓前缀就是指在单词的开原创 2016-04-10 14:21:28 · 2474 阅读 · 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.题目大意: 给定一个罗马数字,将其转化为一个整数。转化好的整数的范围在1---3999之间。思路: 有了上一题的经验,我们可以将待转化的罗马数原创 2016-04-09 19:42:43 · 721 阅读 · 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之间。思路: 在做此题之前特意谷歌了一下罗马数字是什么鬼,因为之前只认识原创 2016-04-09 15:49:41 · 2222 阅读 · 0 评论 -
LeetCode之11---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原创 2016-04-08 18:00:01 · 1310 阅读 · 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 element.The matching should cover the ent原创 2016-04-07 20:22:49 · 971 阅读 · 0 评论 -
LeetCode之9---Palindrome Number
题目: Determine whether an integer is a palindrome. Do this without extra space.题目大意: 判断一个数字是不是回文数,要求不是用额外的空间。思路: 最近的几道LeetCode的题很简单,答题思路就是将原数字翻转然后和原数相比较,如果相等则返回true,否则返回false。但是以前边几道题的尿性来看原创 2016-04-05 22:02:08 · 651 阅读 · 0 评论 -
LeetCode之8----String to Integer (atoi)
题目: Implement atoi to convert a string to an integer.题目大意: 将一个数字字符串转化为整数数字,返回整数数字。思路: 初看本题觉得很简单,直接用一个循环进行转换就行了,循环里边的语句也很简单,就是result = result * 10 + s[i] - '0',但是提交之后就轰轰烈烈的错了。原来是因为我没有考虑各原创 2016-04-05 19:53:14 · 596 阅读 · 0 评论 -
LeetCode之7 --- Reverse Integer
题目: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321题目大意:逆置一个整数,如:123--->321 -123--->-321思路: 这道题比较简单,和回文数的解法一致,只不过比回文数少了一个判断而已。具体思路是循环执行r原创 2016-04-04 18:41:53 · 608 阅读 · 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)P A H原创 2016-04-04 15:19:39 · 602 阅读 · 0 评论 -
LeetCode之338—-Counting Bits
最近上算法课上的有点心塞,所以感觉应该刷刷题来见见世面了,所以选择了LeetCode来做一点题目。LeetCode之338:Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary原创 2016-03-26 15:31:03 · 593 阅读 · 0 评论 -
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.题目大意:给定原创 2016-03-27 15:08:31 · 714 阅读 · 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原创 2016-03-27 15:55:11 · 548 阅读 · 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原创 2016-03-28 23:32:35 · 529 阅读 · 0 评论 -
LeetCode之300—-Longest Increasing Subsequence
题目:Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101原创 2016-03-30 19:03:02 · 749 阅读 · 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)).大意: 两个已原创 2016-03-31 23:53:05 · 567 阅读 · 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.大意:原创 2016-04-03 21:14:08 · 574 阅读 · 0 评论