-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path100. Same Tree.html
More file actions
28 lines (27 loc) · 2.11 KB
/
Copy path100. Same Tree.html
File metadata and controls
28 lines (27 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<html>
<head>
<title>100. Same Tree</title>
<basefont face="Tahoma" size="2" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="exporter-version" content="Evernote Windows/304720 (en-US, DDL); Windows/10.0.14393 (Win64);"/>
<style>
body, td {
font-family: Tahoma;
font-size: 12pt;
}
</style>
</head>
<body>
<a name="2009"/>
<h1>100. Same Tree</h1>
<div>
<table bgcolor="#D4DDE5" border="0">
<tr><td><b>Created:</b></td><td><i>11/29/2016 9:26 AM</i></td></tr>
<tr><td><b>Updated:</b></td><td><i>11/29/2016 9:39 AM</i></td></tr>
<tr><td><b>Tags:</b></td><td><i>depth first search, Easy, leetcode tag, Tree</i></td></tr>
</table>
</div>
<br/>
<div>
<span><div>my solution</div><div style="-en-codeblock: true; box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial;"><div>/**</div><div> * Definition for a binary tree node.</div><div> * public class TreeNode {</div><div> * int val;</div><div> * TreeNode left;</div><div> * TreeNode right;</div><div> * TreeNode(int x) { val = x; }</div><div> * }</div><div> */</div><div>public class Solution {</div><div> public boolean isSameTree(TreeNode p, TreeNode q) {</div><div> if (p == null && q == null ) {</div><div> return true;</div><div> } else if (p == null || q == null) {</div><div> return false;</div><div> }</div><div><br/></div><div> if (p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right)) {</div><div> return true;</div><div> }</div><div> return false;</div><div> }</div><div>}</div></div><div><br/></div></span>
</div></body></html>