Open Zheaoli opened 2 years ago
/*
* @lc app=leetcode id=101 lang=typescript
*
* [101] Symmetric Tree
*/
// @lc code=start
/**
* Definition for a binary tree node.
* class TreeNode {
* val: number
* left: TreeNode | null
* right: TreeNode | null
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
* }
*/
// abstract class TreeNode {
// val: number
// left: TreeNode | null
// right: TreeNode | null
// }
function isSymmetric(root: TreeNode | null): boolean {
let [l = null, r = null] = [root?.left, root?.right];
const walk = (l: TreeNode | null, r: TreeNode | null) => {
if (!l && !r) return true;
if (!l || !r) return false;
return l.val === r.val
&& walk(l.left, r.right)
&& walk(l.right, r.left);
}
return walk(l, r);
};
// @lc code=end
微信id: 弘树 来自 vscode 插件
class Solution {
public List<String> stringMatching(String[] words) {
List<String> ans = new ArrayList<>();
Arrays.sort(words, (o1, o2) -> o2.length() - o1.length());
for (int i = 1; i < words.length; i++) {
for (int j = 0; j < i; j++) {
if (words[j].contains(words[i])) {
ans.add(words[i]);
break;
}
}
}
return ans;
}
}
WeChat: Saraad
2022-08-06