首页
学习
活动
专区
圈层
工具
发布

面试

原创
作者头像
用户7010091
修改2020-02-28 19:04:38
修改2020-02-28 19:04:38
3550
举报

面试题

1. Largest Sum Contiguous Subarray

def maxSubArraySum(a,size):

return max_so_far

2. check if a binary tree is BST or not

# Python program to check if a binary tree is bst or not

# A binary tree node

class Node:

# Constructor to create a new node

def __init__(self, data):

self.data = data

self.left = None

self.right = None

# Returns true if the given tree is a binary search tree

# (efficient version)

def isBST(node):

return (isBSTUtil(node, INT_MIN, INT_MAX))

# Retusn true if the given tree is a BST and its values

# >= min and <= max

def isBSTUtil(node, mini, maxi):

# Driver program to test above function

root = Node(4)

root.left = Node(2)

root.right = Node(5)

root.left.left = Node(1)

root.left.right = Node(3)

if (isBST(root)):

print "Is BST"

else:

print "Not a BST"

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档