lintCode 入门题 python版解答

来源:互联网 发布:怎么样宣传淘宝店铺 编辑:程序博客网 时间:2024/06/07 11:41

献给我的人生第二春,下面开始问题与答案

  1. 矩阵面积

class Rectangle():    '''     * Define a constructor which expects two parameters width and height here.    '''    width = 0.1    height= 0.1    # write your code here    def __init__(self, width,height):        self.width = width        self.height = height        '''     * Define a public method `getArea` which can calculate the area of the     * rectangle and return.    '''    # write your code here    def getArea(self):        return self.width*self.height

2.二叉树遍历

二叉树原理点击打开链接

其它解答http://www.cnblogs.com/bozhou/p/LintCode.html

  LintCode已实现NodeTree类,传入的参数实际为一个NodeTree类型的二叉树,没有找到方法接触源码,只能通过网页一步一步调试,分析出结构:
其中,Node节点类拥有三个属性
  left:当前节点的左节点
  right:当前节点的右节点
  val:当前节点的值
class Solution:    """    @param: root: the root of tree    @return: the max node    """    maxVal = -9999    node = None    # write your code here    def maxNode(self, root):        if root == None:            return None        self.max(root)        return self.node        def max(self,node):        if node == None:            return None        if node.val > self.maxVal:            self.node = node            self.maxVal = node.val        self.max(node.left)        self.max(node.right)

3 ,整数排序

class Solution:    """    @param: A: an integer array    @return:     """    def sortIntegers(self, A):        # write your code here        for i in range(len(A)-1):            for j in range(len(A)-i-1):                if A[j]>A[j+1]:                    B=A[j]                    A[j]=A[j+1]                    A[j+1]=B        return A




原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 个人支票丢了怎么办 鼻子长巨大脓包怎么办 微信里怎么提现怎么办 天猫账号被风控怎么办 618津贴不够用怎么办 天猫精灵不灵敏怎么办 淘宝被恶意退款怎么办 天猫红包失效怎么办 预约人数满了怎么办 淘宝签证拒签怎么办 天猫美的差评怎么办 直通车欠费三块怎么办 上海个人户口卡怎么办 网购信息泄露怎么办 单张券达到上限怎么办 未成年偷钱充q币怎么办 被香港中炎骗了怎么办 房东要收回店面怎么办 天猫字迹模糊怎么办 淘宝类目不叫上架怎么办 淘宝直播有延迟怎么办 淘宝直播间中奖怎么办 微信扫码付款后卖家不发货怎么办 淘宝打骚扰电话怎么办 淘宝卖家打骚扰电话怎么办 被商家打了怎么办 保底消费入坑怎么办 留党查看到期怎么办 遭遇淘宝控价怎么办 淘宝店没有了怎么办 淘宝店铺运费险不出单怎么办 闲鱼定金被骗怎么办 肯德基团购过期怎么办 word不可以修改怎么办 店铺预售不发货怎么办 埋件设置不符合怎么办 闲鱼付了款卖家不发货怎么办 微信里付了款卖家不发货怎么办 运动鞋穿臭了怎么办 小车陷泥土了怎么办 孩子有心事不说怎么办