首页 > 其他分享 >leetcode-101-easy

leetcode-101-easy

时间:2022-10-19 07:49:32浏览次数:76  
标签:101 return && right easy isSymmetric null leetcode left

Symmetric Tree
思路一: 递归

public boolean isSymmetric(TreeNode left, TreeNode right) {
   if (left == null && right == null) return true;
   if (left == null || right == null) return false;

   return left.val == right.val &&
           isSymmetric(left.left, right.right) &&
           isSymmetric(left.right, right.left);
}

标签:101,return,&&,right,easy,isSymmetric,null,leetcode,left
From: https://www.cnblogs.com/iyiluo/p/16804864.html

相关文章

  • leetcode-136-easy
    SingleNumber思路一:用set过滤,剩下唯一一个就是目标数字publicintsingleNumber(int[]nums){Set<Integer>set=newHashSet<>();for(intnum:num......
  • leetcode-202-easy
    HappyNumber思路一:happynumber的结果完全分类,就两种情况最后的值为1进入循环(用map记录)publicbooleanisHappy(intn){Set<Integer>set=newHash......
  • leetcode-141-easy
    LinkedListCycle思路一:用set记录每个节点的hashCode,如果遇到重复,说明是循环publicbooleanhasCycle(ListNodehead){Set<Integer>set=newHashSet<>();......
  • leetcode-344-easy
    ReverseString思路一:首尾互换publicvoidreverseString(char[]s){intmid=s.length/2;intbegin=0;intend=s.length-1;while(beg......
  • leetcode-263-easy
    UglyNumber思路一:从数字中依次去除2,3,5,查看剩余的值是否为1publicbooleanisUgly(intn){if(n==0)returnfalse;while(n%2==0){n/......
  • leetcode-217-easy
    ContainsDuplicate思路一:Set检测publicstaticbooleancontainsDuplicate(int[]nums){Set<Integer>set=newHashSet<>();for(intnum:nums){......
  • leetcode-709-easy
    ToLowerCase思路一:遍历,遇到A-Z范围内的char转换到对应a-z范围publicStringtoLowerCase(Strings){if(s==null||s.isEmpty())returns;int......
  • leetcode-415-easy
    AddString思路一:模拟加法运算,字符串前面填零publicStringaddStrings(Stringnum1,Stringnum2){intmax=Math.max(num1.length(),num2.length());nu......
  • leetcode-389-easy
    FindtheDifference思路一:xor两个字符串publiccharfindTheDifference(Strings,Stringt){charresult=0;for(inti=0;i<s.length();i++){......
  • leetcode-226-easy
    InvertBinaryTree思路一:递归,交换左右。这题比较出名,个人感觉面试的题目和实际工作中遇到的问题还是不太一样的,所以一点准备都不做就跑去面试,答不上来很正常。一般能力......