首页 > 其他 > 详细

leetcode date2018/4/7

时间:2018-04-07 17:03:21      阅读:198      评论:0      收藏:0      [点我收藏+]

(1)

技术分享图片

class Solution:
    def reverseString(self, s):
        """
        :type s: str
        :rtype: str
        """
        return ‘‘.join(list(reversed(s)))
class Solution:
    def reverseString(self, s):
        """
        :type s: str
        :rtype: str
        """
        return s[::-1]

(2)

技术分享图片

class Solution:
    def fizzBuzz(self, n):
        """
        :type n: int
        :rtype: List[str]
        """
        return [str(i)*(i%3!=0 and i%5!=0)+"Fizz"*(i%3==0)+"Buzz"*(i%5==0) for i in range(1,n+1)]
    #*指定参数宽度或精度

(3) 

技术分享图片

 

from collections import Counter
class Solution:
    def singleNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        a = Counter(nums)
        for k,i in a.items():
            if i < 2:
                return k

(4)

技术分享图片

# Definition for a binary tree node.
# class TreeNode:
#    def __init__(self, x):
#        self.val = x
#        self.left = None
#        self.right = None

class Solution:
    def maxDepth(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        return 1 + max(map(self.maxDepth, (root.left, root.right))) if root else 0

 

leetcode date2018/4/7

原文:https://www.cnblogs.com/proven/p/8733485.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!