-
-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sherali Obidov
committed
Jul 22, 2018
1 parent
45f81c2
commit 61ec7e8
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package problems.easy; | ||
|
||
import problems.utils.TreeNode; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Why Did you create this class? what does it do? | ||
*/ | ||
public class LeafSimilarTrees { | ||
public boolean leafSimilar(TreeNode x, TreeNode y) { | ||
if (x == null || y == null) | ||
return x == y; | ||
|
||
List<Integer> l = new ArrayList<>(); | ||
List<Integer> l2 = new ArrayList<>(); | ||
dfs(x, l); | ||
dfs(y, l2); | ||
|
||
if (l.size() != l2.size()) | ||
return false; | ||
|
||
for (int i = 0; i < l.size(); i++) { | ||
if (l.get(i) != l2.get(i)) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
void dfs(TreeNode x, List<Integer> list) { | ||
if (x == null) | ||
return; | ||
if (x.left == null && x.right == null) { | ||
list.add(x.val); | ||
return; | ||
} | ||
dfs(x.left, list); | ||
dfs(x.right, list); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/problems/medium/LongestWordinDictionarythroughDeleting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package problems.medium; | ||
|
||
import problems.utils.TreeNode; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
|