
LeetCode[python]
rayna_Fighting
这个作者很懒,什么都没留下…
展开
-
[leetcode BY python]1两数之和
给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。示例:给定 nums = [2, 7, 11, 15], target = 9因为 nums[0] + nums[1] = 2 + 7 = 9 所以返回 [0, 1]解题方法:cla...原创 2020-02-27 23:01:13 · 224 阅读 · 0 评论 -
[LeetCode BY Python]160. Intersection of Two Linked Lists
题目:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2018-02-06 22:31:32 · 284 阅读 · 0 评论 -
[LeetCode By Python]136. Single Number
题目:Given an 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 with原创 2018-02-06 16:21:47 · 260 阅读 · 0 评论 -
[LeetCode By Python]125. Valid Palindrome
题目:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is原创 2018-02-06 01:56:57 · 255 阅读 · 0 评论 -
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
题目:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie,原创 2018-02-06 01:27:13 · 249 阅读 · 0 评论 -
[LeetCode By Python]121. Best Time to Buy and Sell Stock
题目:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share o原创 2018-02-06 01:15:08 · 262 阅读 · 0 评论 -
[LeetCode By Python]119. Pascal's Triangle II
题目:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?代码:原创 2018-02-06 00:53:31 · 383 阅读 · 0 评论 -
[LeetCode By Python]118. Pascal's Triangle
题目:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]da代码+调试:clas原创 2018-02-06 00:46:15 · 354 阅读 · 0 评论 -
[LeetCode By Python]70. Climbing Stairs
题目:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a原创 2018-01-29 20:33:03 · 223 阅读 · 0 评论 -
[Leetcode By Python]69. Sqrt(x)
题目:Implement int sqrt(int x).Compute and return the square root of x.x is guaranteed to be a non-negative integer.Example 1:Input: 4Output: 2Example 2:Input: 8Output: 2Explan原创 2018-01-29 19:22:19 · 282 阅读 · 0 评论 -
[LeetCode By Python]67. Add Binary
题目:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".代码+调试:class Solution(object): def addBinary(self, a原创 2018-01-29 18:47:44 · 190 阅读 · 0 评论 -
[LeetCode By Python]141. Linked List Cycle
题目:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?解释:判断链表是否有环,如果可以用额外空间,可以使用字典记录键的次数,大于1则存在环。现有情况下可以用快慢指针方法,慢指针走一步,原创 2018-02-06 17:02:52 · 379 阅读 · 0 评论 -
[LeetCode BY Python]155. Min Stack
题目:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top(原创 2018-02-06 18:41:31 · 328 阅读 · 0 评论 -
[leetcode BY python]191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000000000...原创 2018-04-11 00:56:57 · 383 阅读 · 0 评论 -
[Leetcode BY python ]190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 0011100101111...原创 2018-04-11 00:47:59 · 233 阅读 · 0 评论 -
[LeetCode By Python]189. Rotate Array
题目:Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as you can, th...原创 2018-02-08 15:24:27 · 665 阅读 · 0 评论 -
[LeetCode By MYSQL] Combine Two Tables
题目:Table: Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName | varchar |+-------------+---------+Pe...原创 2018-02-08 14:41:05 · 287 阅读 · 0 评论 -
[LeetCode By Python]172. Factorial Trailing Zeroes
题目:Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.解释:求阶乘后0的个数,如果使用暴力可能会超出范围,而且速度会很慢。分析题目特点0的个数,即n!有多少个10,10又可以分解为2*5,2很充足,就...原创 2018-02-08 14:29:55 · 804 阅读 · 0 评论 -
[LeetCode By Python]171. Excel Sheet Column Number
题目:Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3原创 2018-02-07 14:56:14 · 271 阅读 · 0 评论 -
[LeetCode BY Python]169. Majority Element
题目:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority e原创 2018-02-07 14:07:03 · 276 阅读 · 0 评论 -
[LeetCode By Python]168. Excel Sheet Column Title
题目:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB原创 2018-02-07 13:26:20 · 274 阅读 · 0 评论 -
[LeetCode By Python]167. Two Sum II - Input array is sorted
题目:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two原创 2018-02-06 23:11:24 · 428 阅读 · 0 评论 -
[LeetCode By Python]66. Plus One
题目:Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The原创 2018-01-29 16:47:31 · 245 阅读 · 0 评论 -
[LeetCode By Python]58. Length of Last Word
题目:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A wo原创 2018-01-28 20:51:07 · 224 阅读 · 0 评论 -
[LeetCode By Python]53. Maximum Subarray
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-原创 2018-01-28 19:34:05 · 295 阅读 · 0 评论 -
[leetCode By Python] 14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str]原创 2018-01-26 00:06:31 · 237 阅读 · 0 评论 -
[leetCode By python]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.For example:Given binary tr原创 2018-02-01 23:51:07 · 247 阅读 · 0 评论 -
[leetCode By Python]101. Symmetric Tree
题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3原创 2018-02-01 23:28:07 · 252 阅读 · 0 评论 -
[leetCode By Python]100. Same Tree
题目:Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.原创 2018-02-01 23:07:36 · 260 阅读 · 0 评论 -
88. Merge Sorted Array
题目:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hol原创 2018-02-01 22:47:50 · 179 阅读 · 0 评论 -
[LeetCode By Python]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.这里说一下罗马数的简单规则,左边的数>右边的数时,两个数相加,左边的数"DCXXI" = 621romanToint = {'I':1,'V':5,原创 2018-01-25 23:09:58 · 195 阅读 · 0 评论 -
[LeetCode By Python]83. Remove Duplicates from Sorted List
题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.代码+调试:class Li原创 2018-02-01 21:36:27 · 198 阅读 · 0 评论 -
[LeetCode By Python]9. Palindrome Number
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 integer to stri原创 2018-01-23 18:47:10 · 241 阅读 · 0 评论 -
[LeetCode By Python]7 Reverse Integer
题目:Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21原创 2018-01-22 15:46:18 · 182 阅读 · 0 评论 -
[LeetCode By Python]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原创 2018-01-26 01:46:48 · 222 阅读 · 0 评论 -
[LeetCode By Python] 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->3->4Output: 1->1->原创 2018-01-26 20:16:19 · 245 阅读 · 0 评论 -
[LeetCode By Python]107. Binary Tree Level Order Traversal II
题目:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,null原创 2018-02-04 12:59:05 · 415 阅读 · 0 评论 -
[LeetCode By Python]38. Count and Say
题目:The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11原创 2018-01-28 16:55:20 · 271 阅读 · 0 评论 -
[leetcode By Python]strStr
题目:Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2原创 2018-01-28 14:46:30 · 234 阅读 · 0 评论 -
[LeetCode By python]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原创 2018-01-28 16:15:50 · 182 阅读 · 0 评论