100. Same Tree--LeetCode Record
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
/**
* Definition for a binary tree node.
* public class TreeNode {
* public var val: Int
* public var left: TreeNode?
* public var right: TreeNode?
* public init(_ val: Int) {
* self.val = val
* self.left = nil
* self.right = nil
* }
* }
*/
class Solution {
func isSameTree(p: TreeNode?, _ q: TreeNode?) -> Bool {
if p == nil && q == nil {
return true
}else if p == nil || q == nil {
return false
}else if p?.val == q?.val {
return isSameTree(p?.left, q?.left) == true && isSameTree(p?.right, q?.right) == true
}else {
return false
}
}
}
相關文章
- Leetcode 100. Same TreeLeetCode
- 104. Maximum Depth of Binary Tree--LeetCode RecordLeetCode
- 226. Invert Binary Tree--LeetCode RecordLeetCode
- #100. 矩陣乘法矩陣
- Clone a database on the same serverDatabaseServer
- leetcode 100.相同的樹 JavaLeetCodeJava
- B. Same Parity Summands
- Leetcode Same TreeLeetCode
- [ 答朋友問] same namespace ?namespace
- react-recordReact
- [leetcode]same-treeLeetCode
- c++11:std::is_sameC++
- ACM Same binary weightACM
- Leetcode-Same TreeLeetCode
- Same Tree leetcode javaLeetCodeJava
- Using Multiple Variables with the Same Name
- Daily record-SeptemberAI
- Different AG groups have the exactly same group_id value if the group names are same and the ‘CLUSTER_TYPE = EXTERNAL/NONE’None
- 實戰 Java 16 值型別 Record - 2. Record 的基本用法Java型別
- pl/sql record 詳解SQL
- delete duplication record in sql serverdeleteSQLServer
- The fundamental idea remains the same as previous yearsIdeaREMAI
- react fake double , bind click and dblclick on the same elementReact
- Java 16 新特性:record類Java
- Erlang中的Record詳解
- 淺析 record 使用場景
- Record It for Mac錄屏軟體Mac
- Java 21 新特性:Record PatternsJava
- 脫離rails 使用Active RecordAI
- Homework record-Simple sorting
- Leetcode 967 Numbers With Same Consecutive DifferencesLeetCode
- 關於同源策略(Same-origin policy)
- Under the same directory(folder) copy or rename with the different extension name
- [Drupal] multi site with subdomain running the same code in DrupalAI
- SCAN , virtual IP , and public IP must all be on the same subnet
- Warning:dns_get_record():AtemporaryservererroroccurredDNSServerError
- Record for Individual Project ( Word frequency program )Project
- Using Statspack to Record Explain Plan DetailsAI