lintCode 入门题 python版解答
来源:互联网 发布:怎么样宣传淘宝店铺 编辑:程序博客网 时间:2024/06/07 11:41
献给我的人生第二春,下面开始问题与答案
矩阵面积
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
阅读全文
0 0
- lintCode 入门题 python版解答
- LintCode 跳跃游戏 解答
- Coursera 零基础Python入门系列课程习题解答
- LintCode刷题记录入门题汇总
- python挑战题(转+个人解答)
- Lintcode(入门)463
- LintCode【入门】整数排序
- LintCode【入门】斐波纳契数列
- lintcode-入门-整数排序
- lintcode-入门-斐波纳契数列
- LintCode刷题(入门篇)
- Android开发入门解答
- [LintCode]Fibonacci(Python)
- [LintCode]Anagrams(Python)
- [LintCode]Remove Element(Python)
- LintCode Python 统计数字
- LintCode 字符串置换 python
- LintCode 移动零 python
- vue警告问题
- 从svn上拉下来的maven工程少jar包
- 代理proxy获取客户端真实IP
- 在ubuntu中出现Call to undefined function: mysql_connect()
- node.js依赖版本号范围
- lintCode 入门题 python版解答
- 集合运算
- Python--matplotlib绘图可视化知识点整理
- java 调用地图接口
- 返回给定绝对路径的,简化绝对路径
- Hessian 原理分析
- React Native 不规则cell渲染布局
- 前端的痛点之与后台和产品经理的协作
- React-Native初始化环境配置及如何去运行一个helloword工程