For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 【解答】checkBalanced 方法用来递归检查是否平衡的,返回树高度,偷了个巧,如
持续更新... 题目网址:https://leetcode.com/problemset/all/?difficulty=Easy 1.Two Sum[4ms] 2. Reverse Integer [12ms] 题意:将一个32bit signed integer反转输出,如果反转之后超出32位补码范围 [-2^31,2^31-1],则输出0 思路:边取模边算结果,结果存longlong判界 3. Palindrome Number [112ms] 题...
Simply put, Leetcode's popularity has soared to the point where it's virtually a household name. Thousands of interview candidates use it for preparation and seem successful. Leetcode provides problem descriptions, solutions examples, and automatic tests for submitted code — just what we need. ...
LeetCode - 128. Longest Consecutive Sequence (哈希表) LeetCode - 128. Longest Consecutive Sequence (哈希表) 题目链接 题目 解析 第一种方法: 使用一个HashSet来存储对应的值,一开始先将所有的值都加入set; 遍历数组的每一个元素,每次去检查当前元素num的前一个元素num - 1是不是在set中,如果是,说明...
终于刷完了leetcode的前250道题的easy篇。好吧,其实也就60多道题,但是其中的套路还是值得被记录的。 至于全部code,请移步github,题目大部分采用python3,小部分使用C,如有问题和建议,欢迎指正。 String 有一个string库,可以返回各种string的汇总,很值得用。
今天正是开始刷LeetCoded的题目了。计划先开始用python刷Easy的题,一下会记录题目和相关解析。 ---2018/03/08--- 女神节快乐!一大早起来刷题,就是满足感爆棚! 53 - Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For ...
LeetCode最优解, 使用快慢指针思想找循环; 弗洛伊德环检测算法I see the majority of those posts use hashset to record values. Actually, we can simply adapt the Floyd Cycle detection algorithm. I believe that many people have seen this in the Linked List Cycle detection problem. The following is...
题目链接:https://leetcode-cn.com/problems/compress-string-lcci/ 思路 非常简单的题,模拟机器处理过程,一步一步做即可。 class Solution { public: string compressString(string S) { int len = S.size(); if(len==0) return S; string res = ""; int cnt = 1; char ch = S[0]; for(int ...
只出现一次的数字 II 中等 [leetcode-137](leetcode-cn.com/problem) 找出数组中消失的数字 简单 [leetcode-448](leetcode-cn.com/problem) 数组中重复的数据 简单 [leetcode-448](leetcode-cn.com/problem) | 其他小知识 几个有趣的位操作 1. 利用或操作 | 和空格将英文字符转换为小写 ('a' | ' ...
LeetCode刷题记录(easy难度21-40题) leetcode刷题记录 本文记录一下leetcode刷题记录,记录一下自己的解法和心得。 LeetCode Binary Tree Level Order Traversal II 题目:Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, ...