lintcode中python答案
xuebi330ml
这个作者很懒,什么都没留下…
展开
-
lintcode 22.平面列表
class Solution(object): # @param nestedList a list, each element in the list # can be a list or integer, for example [1,2,[1,2]] # @return {int[]} a list of integer def flatten(self, nest...原创 2018-02-26 17:16:55 · 210 阅读 · 0 评论 -
lintcode 41.最大子数组
class Solution: def maxSubArray(self, nums): if nums is None or len(nums) == 0: return 0 maxSum = nums[0] minSum = 0 sum = 0 for num in nums: ...原创 2018-03-14 14:29:38 · 189 阅读 · 0 评论 -
lintcode 78.最长公共前缀
class Solution: """ @param strs: A list of strings @return: The longest common prefix """ def longestCommonPrefix(self, strs): # write your code here for element in strs: ...原创 2018-03-14 13:19:33 · 200 阅读 · 0 评论 -
lintcode 57.三数之和
class Solution: """ @param numbers: Give an array numbers of n integer @return: Find all unique triplets in the array which gives the sum of zero. """ def threeSum(self, numbers): ...原创 2018-03-13 16:01:27 · 202 阅读 · 0 评论 -
lintcode 12.带最小值操作的栈
class MinStack: def __init__(self): # do intialization if necessary self.stack=[] self.minstack=[] """ @param: number: An integer @return: nothing """ def pu...原创 2018-03-12 19:14:50 · 175 阅读 · 0 评论 -
lintcode 30.插入区间
"""Definition of Interval.class Interval(object): def __init__(self, start, end): self.start = start self.end = end"""class Solution: """ Insert a new interval into a sorted non...原创 2018-03-12 15:28:11 · 250 阅读 · 0 评论 -
lintcode 14.二分查找
'''超时了,很扎心'''class Solution: """ @param nums: The integer array. @param target: Target to find. @return: The first position of target. Position starts from 0. """ def binary...原创 2018-02-23 21:19:58 · 332 阅读 · 0 评论 -
lintcode 13.字符串查找
class Solution: """ @param: source: source string to be scanned. @param: target: target string containing the sequence of characters to match @return: a index to the first occurrence o...原创 2018-02-23 20:48:03 · 399 阅读 · 0 评论 -
lintcode 9.fizz buzz问题
class Solution: """ @param n: An integer @return: A list of strings. """ def fizzBuzz(self, n): # write your code here m="fizz" l="buzz" h="fizz buz.原创 2018-02-23 20:28:46 · 185 阅读 · 0 评论 -
lintcode 8.旋转字符串
class Solution: """ @param str: An array of char @param offset: An integer @return: nothing """ def rotateString(self, s, offset): # write your code here newstr...原创 2018-02-21 10:18:59 · 245 阅读 · 0 评论 -
lintcode 2.尾部的零
class Solution: """ @param: n: An integer @return: An integer, denote the number of trailing zeros in n! """ def trailingZeros(self, n): # write your code here, try to do i...原创 2018-02-20 12:04:46 · 220 阅读 · 0 评论 -
lintcode 6.合并并排序数组
class Solution: """ @param A: sorted integer array A @param B: sorted integer array B @return: A new sorted integer array """ def mergeSortedArray(self, A, B): # write ...原创 2018-02-21 09:12:33 · 190 阅读 · 0 评论 -
lintcode 3.统计数字
class Solution: """ @param: : An integer @param: : An integer @return: An integer denote the count of digit k in 1..n """ def digitCounts(self, k, n): # write your cod...原创 2018-02-20 14:30:54 · 255 阅读 · 0 评论 -
lintcode 463.整数排序
class Solution: """ @param A: an integer array @return: nothing """ def sortIntegers(self, A): # write your code here return A.sort()原创 2018-02-20 10:59:00 · 279 阅读 · 0 评论 -
lintcode 366.斐波那契数列
class Solution: """ @param n: an integer @return: an ineger f(n) """ def fibonacci(self, n): # write your code here n1=0 n2=1 if n==1: r...原创 2018-02-19 20:57:07 · 184 阅读 · 0 评论 -
lintcode 454.矩阵面积
class Rectangle: ''' * Define a constructor which expects two parameters width and height here. ''' # write your code here ''' * Define a public method `getArea` which ...原创 2018-02-19 20:54:57 · 346 阅读 · 0 评论 -
lintcode 46.主元素
class Solution: """ @param: nums: a list of integers @return: find a majority number """ def majorityNumber(self, nums): # write your code here A = None count = 0 ...原创 2018-03-20 17:33:31 · 184 阅读 · 0 评论