LeetCode
文章平均质量分 52
stlst
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
[LeetCode] 193. Valid Phone Numbers
Problem Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers.You may assume that a valid phone number must appe原创 2017-12-19 18:05:01 · 341 阅读 · 0 评论 -
[Leetcode] 12. Integer to Roman
Problem:思路: 题目只要求讨论1-3999,所以直接穷举各种情况吧,从千位,百位,十位到个位。Solution:# -*- coding: utf-8 -*-"""Created on Thu Jan 26 11:36:04 2017@author: liangsht"""class Solution(object): def intToRoman(self, num):原创 2017-01-26 12:55:46 · 211 阅读 · 0 评论 -
[Leetcode] 13. Roman to Integer
Problem: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.思路: 方法与LeetCode 12题同理。Solution:class Solution(object): def romanToInt(self原创 2017-01-26 13:33:30 · 232 阅读 · 0 评论 -
[Leetcode] 22. Generate Parentheses
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: [ “((()))”, “(()()原创 2017-02-23 01:28:43 · 331 阅读 · 0 评论 -
[Leetcode] 26. Remove Duplicates from Sorted Array
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 in原创 2017-03-03 10:51:37 · 308 阅读 · 0 评论 -
[Leetcode] 14. Longest Common Prefix
Problem: Write a function to find the longest common prefix string amongst an array of strings.思路: 1. 纵向遍历法。遍历字符串list strs中,每个str的相同index。如果相同则继续,如果不同则跳出循环。遍历完了strs中i个str之后,index自增1,继续重新遍历。时间复杂度O(n原创 2017-02-02 16:47:35 · 345 阅读 · 0 评论 -
[Leetcode] 19. Remove Nth Node From End of List
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原创 2017-02-15 17:03:18 · 316 阅读 · 0 评论 -
[Leetcode] 28. Implement strStr()
Problem: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Idea: Use two points to go through these two string individu原创 2017-03-08 20:58:02 · 291 阅读 · 0 评论 -
[Leetcode] 27. Remove Element
Problem: 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 m原创 2017-03-06 10:56:08 · 279 阅读 · 0 评论 -
[Leetcode] 11. Container With Most Water
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 (i, 0). Fi原创 2017-01-26 12:52:09 · 234 阅读 · 0 评论 -
[Leetcode] 195. Tenth Line
Problem How would you print just the 10th line of a file?For example, assume that file.txt has the following content: Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8原创 2017-12-20 14:40:09 · 260 阅读 · 0 评论 -
[Leetcode] 192. Word Frequency
ProblemWrite a bash script to calculate the frequency of each word in a text file words.txt.For simplicity sake, you may assume:words.txt contains only lowercase characters and space ’ ’ characters.E原创 2017-12-21 11:42:17 · 322 阅读 · 0 评论 -
[Leetcode] 194. Transpose File
Problem Given a text file file.txt, transpose its content.You may assume that each row has the same number of columns and each field is separated by the ’ ’ character.For example, if file.txt has the原创 2017-12-21 16:15:02 · 492 阅读 · 0 评论 -
[Leetcode] 46. Permutations
ProblemGiven a collection of distinct numbers, return all possible permutations.For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1],原创 2018-01-24 15:38:46 · 244 阅读 · 0 评论 -
[Leetcode] 31. Next Permutation
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 lowest ...原创 2018-02-26 23:52:04 · 198 阅读 · 0 评论 -
[Leetcode] 32. Longest Valid Parentheses
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 substring is “(...原创 2018-02-28 17:32:41 · 217 阅读 · 0 评论 -
[Leetcode] 33. Search in Rotated Sorted Array
Problem Suppose an array sorted in ascending order 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 f...原创 2018-02-28 23:04:43 · 210 阅读 · 0 评论 -
[Leetcode] 2. Add Two Numbers
Problem: 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 an原创 2017-01-25 20:39:23 · 244 阅读 · 0 评论 -
[Leetcode] 16. 3Sum Closest
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 would ha原创 2017-02-06 12:02:33 · 256 阅读 · 0 评论 -
[Leetcode] 23. Merge k Sorted Lists
Problem: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Idea:General solution (the same as Merge 2 Sorted Lists Question) Use k index to record原创 2017-02-27 18:16:19 · 249 阅读 · 0 评论 -
[Leetcode] 24. Swap Nodes in Pairs
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 const原创 2017-02-27 21:28:05 · 231 阅读 · 0 评论 -
[Leetcode] 20. Valid Parentheses
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 "()[]{}" ar原创 2017-02-20 12:00:50 · 268 阅读 · 0 评论 -
[Leetcode] 21. Merge Two Sorted Lists
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.Idea: Basic singly-linked list operation. Use t原创 2017-02-20 12:34:49 · 324 阅读 · 0 评论 -
[Leetcode] 17. Letter Combinations of a Phone Number
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.原创 2017-02-12 13:57:11 · 249 阅读 · 0 评论 -
[Leetcode] 18. 4Sum
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: Th原创 2017-02-13 13:26:20 · 259 阅读 · 0 评论 -
[Leetcode] 1. Two Sum
[Leetcode] 1. Two SumProblem 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原创 2017-01-25 20:31:32 · 312 阅读 · 0 评论 -
[Leetcode] 15. 3Sum
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: The solution set must n原创 2017-02-05 01:27:49 · 481 阅读 · 0 评论 -
[Leetcode] 3. Longest Substring Without Repeating Characters
Problem: 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 a原创 2017-01-25 20:56:27 · 260 阅读 · 0 评论 -
[Leetcode] 25.Reverse Nodes in k-Group
Problem: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If th原创 2017-03-02 14:30:57 · 409 阅读 · 0 评论 -
[Leetcode]5. Longest Palindromic Substring
Problem: 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 al原创 2017-01-26 01:16:26 · 203 阅读 · 0 评论 -
[Leetcode] 6. ZigZag Conversion
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原创 2017-01-26 11:18:48 · 199 阅读 · 0 评论 -
[Leetcode] 7. Reverse Integer
Problem: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here are some good questions t原创 2017-01-26 11:29:08 · 262 阅读 · 0 评论 -
[Leetcode] 8. String to Integer (atoi)
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 possi原创 2017-01-26 11:35:16 · 282 阅读 · 0 评论 -
[Leetcode] 9. Palindrome Number
Problem: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the int原创 2017-01-26 12:48:31 · 273 阅读 · 0 评论
分享