- 博客(71)
- 收藏
- 关注
原创 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 233
原创 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 172
原创 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 215
原创 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 215
原创 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 168
原创 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 143
原创 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 138
原创 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 128
原创 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 246
原创 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 251
原创 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 196
原创 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 199
原创 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 213
原创 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 145
原创 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 147
原创 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 297
原创 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 160
原创 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 131
原创 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 305
原创 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 152
原创 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 132
原创 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
原创 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
原创 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 179
原创 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
原创 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 289
原创 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 579
原创 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 599
原创 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 301
原创 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 249
原创 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 389
原创 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 323
原创 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 286
原创 python leetcode 762. Prime Number of Set Bits in Binary Representation
Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation.(Recall that the number of set bits an integer ha...
2018-05-05 19:31:16 318
原创 python leetcode 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A leaf is a node with no children.求二...
2018-05-05 19:22:59 151
原创 python leetcode 292. Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the...
2018-05-05 19:16:05 166
原创 python leetcode 515. Find Largest Value in Each Tree Row
You need to find the largest value in each row of a binary tree.找出二叉树中每层的最大数。513. Find Bottom Left Tree Value637. Average of Levels in Binary TreeExample:Input: 1 / \ 3 ...
2018-05-04 18:14:49 393
原创 python leetcode 136. Single Number
Given a non-empty array of integers, every element appears twice except for one. Find that single one.找出列表中只出现一次的数。Note:Your algorithm should have a linear runtime complexity. Could you implement it w...
2018-05-04 18:05:26 265
原创 python leetcode 693. Binary Number with Alternating Bits
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.判断正整数的二进制数是否全为交替位。也就是说只要存在“00”或者“11”即为否。Example 1:Input: 5Output: True...
2018-05-04 17:54:07 352
原创 python leetcode 521. Longest Uncommon Subsequence I
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. The longest uncommon subsequence is defined as the longest subsequence of one of these str...
2018-05-04 17:49:35 199
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人