LeetCode No.100,101,102】的更多相关文章

No.100 IsSameTree 相同的树 题目 给定两个二叉树,编写一个函数来检验它们是否相同. 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的. 示例 输入: 1 1 / \ / \ 2 3 2 3 [1,2,3], [1,2,3] 输出: true 输入: 1 1 / \ 2 2 [1,2], [1,null,2] 输出: false 输入: 1 1 / \ / \ 2 1 1 2 [1,2,1], [1,1,2] 输出: false 思路 代码 No.101 IsSy…
[LeetCode] Top 100 Liked Questions # Title Acceptance Difficulty 1 Two Sum 38.80% Easy 2 Add Two Numbers 29.10% Medium 3 Longest Substring Without Repeating Characters 25.00% Medium 4 Median of Two Sorted Arrays 23.70% Hard 5 Longest Palindromic Subs…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:刷题顺序,刷题路径,好题,top100,怎么刷题,Leetcode, 力扣,Python, C++, Java 大家好,相信很多朋友在刷题时,看到 LeetCode 的 2000 多道题目,有点手足无措,非常需要一个刷题的顺序和清单. 我整理了在 LeetCode(中文版)上点赞数前 100 的题目,这些的题目基本都在千赞以上,全部都是好题. 举个例子,1…
1.~ wjw$ ssh root@47.103.101.102 ssh: connect to host 47.103.101.102 port 22: Connection refused ssh 服务没有开:按照网上的解决思路: 1.重启 ssh 服务 $sudo service ssh restart 或者 $/etc/init.d/ssh restart 查看服务状态: $ps -ef | grep ssh 结果是空的. 可能原因,ssh client 和server 不匹配 2.重新…
首先表达我对leetcode网站的感谢,与高校的OJ系统相比,leetcode上面的题目更贴近工作的需要,而且支持的语言广泛.对于一些比较困难的题目,可以从讨论区中学习别人的思路,这一点很方便. 经过一段时间的练习,我感觉自己的算法水平还是有很大的提升的.与学校开的算法导论的课程相比,我觉得实实在在的做题,比学习理论更符合我的认知方式.可能我属于那种脑子记不住,但是可以用“肌肉”去记忆的类型吧. 在做题的时候,我会尝试用感觉好玩的语言来写.如果把做题当成一种解谜游戏的话,那语言就是玩这个游戏选择…
Now, I want to just use English to explain the problem, it's about two month before the interview, so I have to practice my oral English more. And I will write my explainations in my code in order to keep this passage looking comfortable. 101. Symmet…
第一题:905. 按奇偶校验排序数组 问题: 给定一个非负整数数组 A,返回一个由 A 的所有偶数元素组成的数组,后面跟 A 的所有奇数元素. 你可以返回满足此条件的任何数组作为答案. 示例: 输入:[3,1,2,4] 输出:[2,4,3,1] 输出 [4,2,3,1],[2,4,1,3] 和 [4,2,1,3] 也会被接受. 提示: 1 <= A.length <= 5000 0 <= A[i] <= 5000 链接:https://leetcode-cn.com/contest…
题目链接:Same Tree | LeetCode OJ 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. Tags: Depth-first Search 分析 很基本的一道深度优…
------------------------------------------ 递归比较即可 AC代码: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public boolean isSa…
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 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…
1 Two Sum Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: Given nums = [2,…
101. Symmetric Tree My Submissions Question Total Accepted: 90196 Total Submissions: 273390 Difficulty: Easy 给定一颗二叉树,检查是否镜像对称(环绕中心对称) Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this bin…
leetcode go语言版本,主要为了熟悉下语言 1. Two Sum 双指针版本, O(NlogN) func twoSum(nums []int, target int) []int { valResult := []int{} indexResult := []int{} i := 0 j := len(nums) - 1 temp := make([]int, len(nums)) copy(temp, nums) sort.Ints(temp) for i < j { if temp…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 [LeetCode] 题目地址:https://leetcode.com/problems/same-tree/ Total Accepted: 126017 Total Submissions: 291619 Difficulty: Easy 题目描述 Given two binary trees, write a function to c…
#-*- coding: UTF-8 -*-# Definition for a binary tree node.# class TreeNode(object):#     def __init__(self, x):#         self.val = x#         self.left = None#         self.right = Noneclass Solution(object):    resultBool=True    def isSymmetric(se…
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. Solution 1:recursion,the key is to find out all situations of retu…
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…
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following [1,2,2,null,3,null,3] is not: 1 / \ 2 2 \ \ 3 3 BFS…
Easy! 题目描述: 给定两个二叉树,编写一个函数来检验它们是否相同. 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的. 示例 1: 输入: 1 1 / \ / \ 2 3 2 3 [1,2,3], [1,2,3] 输出: true 示例 2: 输入: 1 1 / \ 2 2 [1,2], [1,null,2] 输出: false 示例 3: 输入: 1 1 / \ / \ 2 1 1 2 [1,2,1], [1,1,2] 输出: false 解题思路: 判断两棵树是否相同和…
Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical and the nodes have the same value. 即为判断两颗二叉树是否相同.输入是用数组表示的二叉树. 对于图中的树,它的编号是这样的:A(1)B(2)C(3)D(4)…
看到这道题,第一思考是结构和节点完全相同 第一次,就没有思考null的情况 if(p.val == q.val && p.left.val == q.left.val && p.right.val == q.right.val) { return true; } else return false; 这个就导致以下错误,就是空指针的错误 java.lang.NullPointerException at line 12, Solution.isSameTree at lin…
判断输入的两棵树是不是相同 判断当前root值,左子树和右子树是否相同 ####注意最后用的是 is 而不是 ==,因为最后判断p和q是不是None, 应该判断是不是同一个对象 class Solution(object): def isSameTree(self, p, q): if p and q: return self.isSameTree(p.left,q.left) and self.isSameTree(p.right,q.right) and p.val==q.val retur…
Same Tree 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 binary tree * struct TreeNod…
题目 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. 分析 判断两个二叉树是否相同. 采用递归的思想,当节点关键字以及左右子树均相同时,此两颗二叉树才相同: AC代码 /** *…
刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow: F(k…
刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度. 如: 给出[100, 4, 200, 1, 3, 2], 最长的连续元素序列是[1, 2, 3, 4].返回它的长度:4. 你的算法必须有O(n)的时间复杂度 . 解法: 初始思路 要找连续的元素,第一反应一般是先把数组排序.但悲剧的是题目中明确要求了O(n)的时间复杂度,要做一次排序,是不能达…
LeetCode题目解答——Easy部分 Posted on 2014 年 11 月 3 日 by 四火 [Updated on 9/22/2017] 如今回头看来,里面很多做法都不是最佳的,有的从复杂度上根本就不是最优解,有的写的太啰嗦,有的则用了一些过于tricky的方法.我没有为了这个再更新,就让它们去吧. LeetCode最近很火,我以前不太知道有这么一个很方便练习算法的网站,直到大概数周前同事和我说起,正好我老婆要找工作,而根据同事的理论,LeetCode的题目是必须攻破的第一道关卡.…
LeetCode很喜欢sum,里面sum题一堆. 1.Two Sum Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. E…
[LeetCode]386. Lexicographical Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/lexicographical-numbers/description/ 题目描述: Given an integer n, return 1 - n in lexicogra…
1. 题目 2. 解答 2.1 方法一 假设返回 118 以内数的字典顺序,则为 1,10,100,101,102,...,109,11,110,111,112,...,118,12,13,....根据这个序列,我们发现有以下几种情况. 1,10,100,每次都乘以 10 100,101,102,...,109,每次加 1 109,11,末尾为 9 则先除以 10 直到末尾不为 9 再加 1 118,12,排到 n 了则先除以 10 再加 1 class Solution { public: v…