6 kyu

Binary Tree Compare

908 of 1,950bovard

Description:

Given the node object:

Node:
  val: <int>,
  left: <Node> or null,
  right: <Node> or null

write a function compare(a, b) which compares the two trees defined by Nodes a and b and returns true if they are equal in structure and in value and false otherwise.

Examples:

1       1
| \     | \
2  3    2  3
=> true

1       1
| \     | \
3  3    2  3
=> false (values not the same 2 != 3)

1       1
| \     |
2  3    2
        |
        3
=> false (structure not the same)
Binary Trees
Algorithms

Stats:

CreatedJun 19, 2015
PublishedJun 19, 2015
Warriors Trained3783
Total Skips240
Total Code Submissions15032
Total Times Completed1950
JavaScript Completions908
Python Completions911
C Completions131
Lua Completions26
COBOL Completions3
Haskell Completions49
Scala Completions9
Total Stars124
% of votes with a positive feedback rating94% of 314
Total "Very Satisfied" Votes283
Total "Somewhat Satisfied" Votes24
Total "Not Satisfied" Votes7
Ad
Contributors
  • bovard Avatar
  • smile67 Avatar
  • ggorlen Avatar
  • JohanWiltink Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • fcr-- Avatar
  • KayleighWasTaken Avatar
Ad