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
}
}
}
相關文章
- 100. Same Tree
- Leetcode 100. Same TreeLeetCode
- leetcode 100.相同的樹 JavaLeetCodeJava
- 100-Same Tree
- [leetcode]same-treeLeetCode
- B. Same Parity Summands
- react-recordReact
- Active Record Associations
- screen-record
- 力扣刷題:100. 相同的樹力扣
- Leetcode 967 Numbers With Same Consecutive DifferencesLeetCode
- The fundamental idea remains the same as previous yearsIdeaREMAI
- c++11:std::is_sameC++
- ES6+ ---- record
- Daily record-SeptemberAI
- Learn and Record12
- Camera List Record - 120
- 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型別
- Travel Notes-Record mood
- Homework record-Simple sorting
- BULK In-BIND與RECORD(轉)
- Renovation Tour-Record my home
- Java 21 新特性:Record PatternsJava
- Record It for Mac錄屏軟體Mac
- gorm忽略報錯: record not foundGoORM
- Java 16 新特性:record類Java
- Erlang中的Record詳解
- 淺析 record 使用場景
- [20190706]Same dog, different leash – functions in SQL.txtFunctionSQL
- [Javascript] Import the Same JavaScript Module Multiple Times with Cache BustingJavaScriptImport
- record:記錄(帶名元組)
- 不好分類的好題Record
- PerconaXtraDBClusterGCache和Record-Set快取GC快取
- hiho一下 第229周:Same Letters In A Row
- Same Origin Policy 瀏覽器同源策略詳解瀏覽器
- JDK14 新增關鍵字——recordJDK
- 如何處理 No DMARC Record Found 問題
- mysql innodb lock鎖之record lock之一MySql