leetcode_python
文章平均质量分 61
DreamerLHQ
这个作者很懒,什么都没留下…
展开
-
python leetcode 13. Roman to Integer
Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-04-04 09:28:27 · 196 阅读 · 0 评论 -
python leetcode 20. Valid Parentheses
Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.有效的括号An input string is valid if:Open brackets must be closed by the same ty...原创 2019-04-04 10:14:27 · 239 阅读 · 0 评论 -
python leetcode 17. Letter Combinations of a Phone Number
Given a string containing digits from2-9inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is giv...原创 2019-04-04 10:13:20 · 245 阅读 · 0 评论 -
python leetcode 14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string"".找到最长的共同前缀Example 1:Input: ["flower","flow","flig...原创 2019-04-04 10:11:46 · 194 阅读 · 0 评论 -
python leetcode 628. Maximum Product of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product.找出列表中三个数乘积最大的结果。将列表升序排序,由于存在负数的情况,则结果为max(最后三个数乘积,负数情况下前面两个数乘积再乘最后一个数)Example 1:Input: [1,2,...原创 2018-11-28 19:34:15 · 165 阅读 · 0 评论 -
python leetcode 551. Student Attendance Record I
You are given a string representing an attendance record for a student. The record only contains the following three characters: 'A' : Absent. 'L' : Late. 'P' : Present. A student could be re...原创 2018-11-28 19:19:12 · 176 阅读 · 0 评论 -
python leetcode 268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. 找到0-n中消失的数字。减法即可 Example 1:Input: [3,0,1]Output: 2Example 2:Inpu...原创 2018-10-30 21:07:57 · 122 阅读 · 0 评论 -
python leetcode 27. Remove Element
Given an array nums and a value val, 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 by modifying the input arra...原创 2018-09-06 20:39:01 · 279 阅读 · 0 评论 -
python leetcode 819. Most Common Word
Given a paragraph and a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at least one word that isn't banned, and that the answer...原创 2018-09-06 20:25:54 · 578 阅读 · 0 评论 -
python leetcode 784. Letter Case Permutation
Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create. 列举出字符串中在字母有大小写两种情况下的所有可能...原创 2018-09-06 20:25:23 · 597 阅读 · 0 评论 -
python leetcode 260. Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.找出列表中两个只出现一次的数。Example:Input...原创 2018-06-09 20:29:35 · 291 阅读 · 0 评论 -
python leetcode 485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.找出列表中连续‘1’的最大个数。Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are co...原创 2018-06-09 20:00:32 · 238 阅读 · 0 评论 -
python leetcode 226. Invert Binary Tree
Invert a binary tree.二叉树反转Example:Input: 4 / \ 2 7 / \ / \1 3 6 9Output: 4 / \ 7 2 / \ / \9 6 3 1# Definition for a binary tree node.# class TreeNode:# ...原创 2018-05-30 21:19:56 · 373 阅读 · 0 评论 -
python leetcode 413. Arithmetic Slices
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequence:1,...原创 2018-05-30 20:52:49 · 315 阅读 · 0 评论 -
python leetcode 537. Complex Number Multiplication
Given two strings representing two complex numbers.You need to return a string representing their multiplication. Note i2 = -1 according to the definition.求两个复数的乘积。Example 1:Input: "1+1i", "1+1i"Outp...原创 2018-05-02 16:12:27 · 210 阅读 · 0 评论 -
python leetcode 821. Shortest Distance to a Character
Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string.找出字符串中与给定字符的最短距离。Example 1:Input: S = "loveleetcode", C = 'e'Outp...原创 2018-05-02 16:11:59 · 759 阅读 · 0 评论 -
python leetcode 806. Number of Lines To Write String
We are to write the letters of a given string S, from left to right into lines. Each line has maximum width 100 units, and if writing a letter would cause the width of the line to exceed 100 units, it...原创 2018-05-02 16:11:43 · 174 阅读 · 0 评论 -
python 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.将两个单向链表按从小到大的顺序融合Example:Input: 1->2->4, 1-&g...原创 2019-04-04 10:15:37 · 125 阅读 · 0 评论 -
python leetcode 22. Generate Parentheses
Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.给定n对括号,编写一个函数来生成所有格式正确的括号组合。For example, givenn= 3, a solution set is:[ "((()))", "...原创 2019-04-04 10:16:34 · 137 阅读 · 0 评论 -
python leetcode 12. Integer to Roman
Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-04-03 15:44:28 · 204 阅读 · 0 评论 -
python leetcode 11. Container With Most Water
Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two...原创 2019-04-03 15:42:38 · 144 阅读 · 0 评论 -
python leetcode 9. Palindrome Number
Determine whether an integer is a palindrome. An integerisapalindrome when itreads the same backward as forward.判断数字是否是回文,其中负数肯定不是回文数字Example 1:Input: 121Output: trueExample 2:Input...原创 2019-04-03 15:41:25 · 144 阅读 · 0 评论 -
python leetcode 8. String to Integer (atoi)
Implementatoiwhichconverts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from thi...原创 2019-04-03 15:40:11 · 289 阅读 · 0 评论 -
python leetcode 7. Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer.将数值从后往前读取,负号保留不动Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321class Solution(object): def revers...原创 2019-04-03 15:38:45 · 157 阅读 · 0 评论 -
python 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 NA P L S I I...原创 2019-04-03 15:33:02 · 127 阅读 · 0 评论 -
python leetcode 5. Longest Palindromic Substring
Given a strings, find the longest palindromic substring ins. You may assume that the maximum length ofsis 1000.最长的回文字符串Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid an...原创 2019-04-03 15:31:44 · 288 阅读 · 0 评论 -
python leetcode 3. Longest Substring Without Repeating Characters
Given a string, find the length of thelongest substringwithout repeating characters.最长的不重复的字符串长度Example 1:Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of 3....原创 2019-04-03 15:30:10 · 147 阅读 · 0 评论 -
python leetcode 2. Add Two Numbers
You are given twonon-emptylinked lists representing two non-negative integers. The digits are stored inreverse orderand each of their nodes contain a single digit. Add the two numbers and return i...原创 2019-04-03 15:27:59 · 127 阅读 · 0 评论 -
python leetcode 1. Two Sum
Given an array of integers, returnindicesof the two numbers such that they add up to a specific target.You may assume that each input would haveexactlyone solution, and you may not use thesame...原创 2019-04-03 15:26:25 · 121 阅读 · 0 评论 -
python leetcode 46. Permutations
# Given a collection of distinct integers, return all possible permutations."""给定一组不同的整数,返回所有可能的排列。Input: [1,2,3]Output: [[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]"""class Solution(...原创 2019-04-08 09:49:01 · 230 阅读 · 0 评论 -
python leetcode 38. Count and Say
# The count-and-say sequence is the sequence of integers with the first five terms as following:# 1. 1# 2. 11# 3. 21# 4. 1211# 5. 111221# 1 is read off as "one 1" or 11.# 1...原创 2019-04-08 09:48:34 · 167 阅读 · 0 评论 -
python leetcode 35. 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 arra...原创 2019-04-04 10:22:40 · 209 阅读 · 0 评论 -
python leetcode 28. Implement strStr()
ImplementstrStr().Return the index of the first occurrence of needle in haystack, or-1if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example...原创 2019-04-04 10:22:00 · 208 阅读 · 0 评论 -
python leetcode 27. Remove Element
Given an arraynumsand a valueval, remove all instances of that valuein-placeand return the new length.Do not allocate extra space for another array, you must do this bymodifying the input arra...原创 2019-04-04 10:19:57 · 166 阅读 · 0 评论 -
python leetcode 26. Remove Duplicates from Sorted Array
Given a sorted arraynums, remove the duplicatesin-placesuch that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this bymodifyi...原创 2019-04-04 10:18:27 · 140 阅读 · 0 评论 -
python leetcode 561. Array Partition I
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as poss...原创 2018-05-02 16:11:26 · 280 阅读 · 0 评论 -
python leetcode 728. Self Dividing Numbers
A self-dividing number is a number that is divisible by every digit it contains.For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.Also, a self-dividing nu...原创 2018-05-02 16:11:10 · 325 阅读 · 0 评论 -
python leetcode 496. Next Greater Element I
You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2.Th...原创 2018-05-04 15:21:16 · 761 阅读 · 2 评论 -
python leetcode 553. Optimal Division
Given a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -> 2 / 3 / 4.However, you can add any number of parenthesis at any position to change ...原创 2018-05-10 20:35:13 · 285 阅读 · 0 评论 -
python leetcode 442. Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without extra spac...原创 2018-05-04 09:25:09 · 193 阅读 · 0 评论