码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode date2018/4/7

时间:2018-04-07 17:39:44      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:图片   分享图片   ini   ems   date   nbsp   reverse   src   tree node   

(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

标签:图片   分享图片   ini   ems   date   nbsp   reverse   src   tree node   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!