Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9a5c65d

Browse files
committed
Add: test case
1 parent b51545e commit 9a5c65d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

‎problems/cousins-in-binary-tree/cousins_in_binary_tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import . "github.com/openset/leetcode/internal/kit"
1313
func isCousins(root *TreeNode, x int, y int) bool {
1414
xp, yp, xd, yd, depth := 0, 0, 0, 0, 0
1515
queue := []*TreeNode{root}
16-
for l := len(queue); l > 0; l = len(queue) {
16+
for l := len(queue); l > 0&&xd==0&&yd==0; l = len(queue) {
1717
for _, node := range queue {
1818
if node.Left != nil {
1919
if node.Left.Val == x {

‎problems/cousins-in-binary-tree/cousins_in_binary_tree_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ func TestIsCousins(t *testing.T) {
3333
y: 3,
3434
expected: false,
3535
},
36+
{
37+
input: []int{1, 2, 3, NULL, 4, 5},
38+
x: 4,
39+
y: 5,
40+
expected: true,
41+
},
42+
{
43+
input: []int{1, 2, 3, NULL, 4, 5},
44+
x: 5,
45+
y: 4,
46+
expected: true,
47+
},
3648
}
3749
for _, tc := range tests {
3850
output := isCousins(SliceInt2TreeNode(tc.input), tc.x, tc.y)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /