![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python学习
Zebma
这个作者很懒,什么都没留下…
展开
-
455. Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a coo原创 2017-04-30 14:55:36 · 133 阅读 · 0 评论 -
Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1code #迭代# Definition for a binary tree node.# class TreeNode(原创 2017-04-25 13:41:45 · 140 阅读 · 0 评论 -
389. Find the Difference
Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was ad原创 2017-04-25 13:46:44 · 173 阅读 · 0 评论 -
409. Longest Palindrome
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example "Aa" is not con原创 2017-05-07 21:53:42 · 107 阅读 · 0 评论 -
217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element原创 2017-05-07 22:07:01 · 118 阅读 · 0 评论 -
258. Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one原创 2017-04-26 14:40:06 · 136 阅读 · 0 评论 -
27. Remove Element
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 memory.原创 2017-05-17 22:07:23 · 115 阅读 · 0 评论 -
350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note:Each element in the result should appear as ma原创 2017-05-09 15:38:40 · 117 阅读 · 0 评论 -
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 digi原创 2017-05-18 15:39:51 · 217 阅读 · 1 评论 -
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原创 2017-05-10 13:57:50 · 160 阅读 · 0 评论 -
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.For example,Given nums = [0, 1, 3] return 2.class Solution(object原创 2017-05-10 14:42:20 · 119 阅读 · 0 评论 -
441. Arranging Coins
You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find the total number of full staircase rows that can be formed.原创 2017-05-19 22:16:41 · 197 阅读 · 0 评论 -
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].杨辉三角:性质:第n行的m个数可表示为 C(n-1,m-1),即为从n-1个不同元素中取m-1个元素的组合数。code:class Soluti原创 2017-05-19 23:13:08 · 127 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
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 place with原创 2017-05-20 15:13:35 · 137 阅读 · 0 评论 -
515. Find Largest Value in Each Tree Row
You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]code:原创 2017-06-16 11:03:02 · 169 阅读 · 0 评论 -
338. Counting Bits
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 representation and return them as an array.Example:For num =原创 2017-06-08 14:44:55 · 151 阅读 · 0 评论 -
451. Sort Characters By Frequency
Given a string, sort it in decreasing order based on the frequency of characters.Example 1:Input:"tree"Output:"eert"Explanation:'e' appears twice while 'r' and 't' both appear once.So 'e原创 2017-06-25 10:50:59 · 192 阅读 · 0 评论 -
575. Distribute Candies
Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute the原创 2017-05-07 15:33:57 · 240 阅读 · 0 评论 -
28. Implement strStr() Add to List
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.code:class Solution(object): def strStr(self, haystac原创 2017-05-25 22:13:28 · 245 阅读 · 0 评论 -
504. Base 7
Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"Note: The input will be in range of [-1e7, 1e原创 2017-05-06 14:08:08 · 204 阅读 · 0 评论 -
Python算法之栈(stack)的实现
本文以实例形式展示了Python算法中栈(stack)的实现,对于学习数据结构域算法有一定的参考借鉴价值。具体内容如下:1.栈stack通常的操作:Stack() 建立一个空的栈对象push() 把一个元素添加到栈的最顶层pop() 删除栈最顶层的元素,并返回这个元素peek() 返回最顶层的元素,并不删除它isEmpty() 判断栈是否为空size()转载 2017-04-19 14:25:41 · 411 阅读 · 0 评论 -
leectcode 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 nums原创 2017-04-19 14:28:56 · 191 阅读 · 0 评论 -
349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return[2].返回两个列表相同的元素 去重的 code:class Solution(object): def i原创 2017-05-01 13:55:31 · 145 阅读 · 0 评论 -
463. Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completel原创 2017-04-19 16:36:26 · 147 阅读 · 0 评论 -
541. Reverse String II
Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of th原创 2017-05-12 14:43:36 · 138 阅读 · 0 评论 -
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, and you may not use the sam原创 2017-05-23 18:07:13 · 132 阅读 · 0 评论 -
290. Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.原创 2017-05-23 18:20:23 · 142 阅读 · 0 评论 -
520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters in thi原创 2017-04-22 18:45:32 · 142 阅读 · 0 评论 -
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"Out原创 2017-05-04 17:37:41 · 183 阅读 · 0 评论 -
405. Convert a Number to Hexadecimal
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.Note:All letters in hexadecimal (a-f) must be in lowercase.The hexade原创 2017-05-13 20:20:50 · 139 阅读 · 0 评论 -
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, b): """原创 2017-05-24 16:27:10 · 165 阅读 · 0 评论 -
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 word is原创 2017-05-24 16:33:35 · 151 阅读 · 0 评论 -
237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2017-05-05 12:39:39 · 110 阅读 · 0 评论 -
326. Power of Three
Given an integer, write a function to determine if it is a power of three.code:class Solution(object): def isPowerOfThree(self, n): """ :type n: int :rtype: boo原创 2017-05-14 15:30:11 · 131 阅读 · 0 评论 -
581. Shortest Unsorted Continuous Subarray
Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You need to fin原创 2017-05-25 14:39:40 · 285 阅读 · 0 评论 -
242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.class Solution原创 2017-05-06 13:41:24 · 126 阅读 · 0 评论 -
python 求两个list的差集,并集和交集
比如,现在有两个list类型:a_list = [1,2,3,4]b_list = [1,4,5]一. 差集很明显结果是[2,3,5],下面我们说一下具体方法。方法a.正常法: ret_list = [] for item in a_list: if item not in b_list: ret_list.append(ite转载 2017-06-27 17:21:28 · 448 阅读 · 0 评论