lintCode 入门题 python版解答
2017-10-24 11:06
344 查看
献给我的人生第二春,下面开始问题与答案
矩阵面积
其它解答http://www.cnblogs.com/bozhou/p/LintCode.html
LintCode已实现NodeTree类,传入的参数实际为一个NodeTree类型的二叉树,没有找到方法接触源码,只能通过网页一步一步调试,分析出结构:
其中,Node节点类拥有三个属性
left:当前节点的左节点
right:当前节点的右节点
val:当前节点的值
矩阵面积
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
相关文章推荐
- Coursera 零基础Python入门系列课程习题解答
- python3 [爬虫入门实战] 查看网站有多少个网页(站点)
- python初级教程:入门详解
- Python学习入门基础教程(learning Python)--3 Python分支结构和布尔逻辑
- 快速入门:十分钟学会Python(转)
- python-入门基础语法
- Python快速入门学习笔记(二)
- JAVA从菜鸟【入门】到新手【实习】一一转入第二语言Python学习,规划与方案
- python 编程从入门到实践 第二章 变量和简单数据类型
- python语法入门
- 十分钟python入门教程
- python入门小结-01
- 在类Unix系统上开始Python3编程入门
- python入门笔记--模块和模块包的调用
- Python入门笔记之字符串
- 用Python和Pygame写游戏-从入门到精通(15)
- Python 入门之旅
- Python入门基础语法之字符串、列表、元组
- Python入门编程的闲杂知识点自结
- Python 零基础 快速入门 趣味教程 (咪博士 海龟绘图 turtle) 4. 函数