6 kyu

Binary Tree Compare

902 of 1,929bovard

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 Trained3750
Total Skips237
Total Code Submissions14909
Total Times Completed1929
JavaScript Completions902
Python Completions903
C Completions125
Lua Completions26
COBOL Completions3
Haskell Completions49
Scala Completions6
Total Stars123
% of votes with a positive feedback rating94% of 311
Total "Very Satisfied" Votes281
Total "Somewhat Satisfied" Votes23
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