提供以下课程;
class TreeNode:
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left
self.right = right
完成功能
def binary_tree_compare(a, b)
# return True if the two binary trees rooted and a and b are equal in value and structure
# return False otherwise
def compare(a, b):
答案 0 :(得分:0)
这是您要寻找的吗?
public class LanguagesComposer : ComponentComposer<LanguagesComponent>
{
public void Compose(Composition composition)
{
composition.Register<IGetLanguagesService>(Lifetime.Singleton);
composition.Register<ILocalizationService>(Lifetime.Singleton);
composition.Components().Append<LanguagesComponent>();
}
}
public class LanguagesComponent : IComponent
{
public void Initialize()
{
???????
}
public void Terminate()
{
throw new NotImplementedException();
}
IGetLanguagesService _getLanguagesService;
ILocalizationService _localization;
public void CallGetLanguages(IGetLanguagesService getLanguages, ILocalizationService localization)
{
_getLanguagesService = getLanguages;
_localization = localization;
_getLanguagesService.GetLanguages(localization);
}
}
答案 1 :(得分:0)
enter code here
def compare(a, b):
#check: both nodes empty => same trees
enter code here
if(a == None and b == None):
enter code here
return True
#check: only one note empty: different trees
enter code here
elif((a == None and b != None) or (a != None and b == None)):
enter code here
return False
#check: node content is the same and all children are the same: same tree
`enter code here`else:
`enter code here` return (a.val == b.val) and (compare(a.left, b.left) and compare(a.right, b.right))