平衡二叉树 LeetCode: "平衡二叉" 题目描述: 给定一个二叉树,判断它是否是高度平衡的二叉树。 示例: 思想: 使用实例域变量记录是否与有不满足平衡的节点出现,使用一次递归即可。 代码 ...
分类:
编程语言 时间:
2020-04-17 11:11:37
阅读次数:
61
题目地址: "https://leetcode cn.com/problems/two sum/" 1.暴力解法 直接双重循环,枚举出所有可能的解,时间复杂度为O(n^2),空间复杂度为O(1) 2.HashTable 第一次循环将数组nums中的每个数都放入map中 第二次循环判断target n ...
分类:
其他好文 时间:
2020-04-17 00:50:56
阅读次数:
61
fgets(char *,int x,file *) (1)一般若读取的字符数小于X-1,且使用换行来结束本行的输入,且换行符也保存在str中; fgets(str[i],61,stdin); 输入59个字符,则str[59] == '\n' 成立; 输入40个字符,则str[40] == '\n' ...
分类:
其他好文 时间:
2020-04-17 00:13:59
阅读次数:
50
题目 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed fo ...
分类:
其他好文 时间:
2020-04-16 13:20:15
阅读次数:
61
LeetCode上的卖股票题大概有6道,建议大家去看一下英文版 LeetCode上关于这类题目的讲解:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/discuss/108870/M ...
分类:
编程语言 时间:
2020-04-16 00:47:04
阅读次数:
88
题目描述:给定一个由 0 和 1 组成的矩阵,找出每个元素到最近的 0 的距离。两个相邻元素间的距离为 1 。 示例 1:输入: 0 0 00 1 00 0 0输出: 0 0 00 1 00 0 0示例 2:输入: 0 0 00 1 01 1 1输出: 0 0 00 1 01 2 1 思路: 题目给 ...
分类:
其他好文 时间:
2020-04-15 21:32:42
阅读次数:
59
传送门:https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/ 给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为:“对于有根树 T 的两个结点 p、q,最近公共祖先表示 ...
分类:
其他好文 时间:
2020-04-15 18:10:47
阅读次数:
71
[TOC] 1. 问题描述 (LeetCode 739. 每日温度)[https://leetcode cn.com/problems/daily temperatures/] 2. 问题分类 栈(单调栈) 3. 问题解析 Reference: https://leetcode cn.com/pro ...
分类:
其他好文 时间:
2020-04-14 23:07:14
阅读次数:
129
题目:https://leetcode cn.com/problems/lfu cache/ 思路: O(1)的数据结构:hashmap 维持最近使用:OrderdDict(详见LRU缓存问题) 使用一个hashmap维系key到出现频率的映射关系 另一个hashmap维系频率到数据(key val ...
分类:
其他好文 时间:
2020-04-14 10:45:26
阅读次数:
62
题目地址:https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/ 题目描述 在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 题目示例 示例: s = "abaccdeff" 返回 ...
分类:
编程语言 时间:
2020-04-14 10:28:44
阅读次数:
71