随笔分类 - Leetcode
leetcode note
摘要:题目:[https://leetcode cn.com/problems/reverse string/description/] 思路:容器的操作,反正给定string即可 代码: 讨论区范例代码: C++ class Solution { public: string reverseString
阅读全文
摘要:题目:[https://leetcode cn.com/problems/number complement/description/] 思路:模拟操作,注意几个点:: 1、计算机中的有符号数值多以(默认全部)以补码的形式储存。 2、补码:正数等于原码,负数等于反码末尾+1 3、反码:正数等于原码,
阅读全文
摘要:题目:[https://leetcode cn.com/problems/peak index in a mountain array/description/] 思路:描述很复杂,实质是找到最大值的位置 讨论区:[https://leetcode.com/problems/peak index i
阅读全文
摘要:题目:[https://leetcode cn.com/problems/unique morse code words/description/] 思路:1、初始化莫斯代码表,字母表 2、翻译每个单词的摩斯码 3、利用stl关联容器统计翻译次数 代码: 讨论区精品代码:
阅读全文
摘要:题目:[https://leetcode cn.com/problems/flipping an image/description/] 思路:翻转:定义一个int变量,头尾迭代器交换内部数据,并完成1\0的替换,头迭代器=尾迭代器或者头迭代器的位置超过为迭代器的时候表示访问完毕,数据处理完成。 讨
阅读全文
摘要:题目:[https://leetcode cn.com/problems/robot return to origin/description/] 思路:直接模拟,记录相应字符出现的次数、统计最后的情况;
阅读全文
摘要:思路:node是一个指针,指向链表中的一个点,本题中,考虑直接修改指针本身,使其指向下一个点即可
阅读全文
摘要:思路:对于对于一个单向链表,顺序访问每个点直到尾端,然后递归回归输出转向链表 代码:
阅读全文
摘要:思路:题目要求统计俩个整形的数字不同二进制位的数目,直接模拟操作 代码 c++ class Solution { public: int hammingDistance(int x, int y) { int line; x=(x
阅读全文
摘要:思路:给出两个二叉树,题目要求合并两个二叉树。两个二叉树的各自的位置上节点都是互相对应的,所以可以明确,以一棵树为基准比较相应位置的值进行合并就好。
阅读全文
摘要:题目:[https://leetcode cn.com/problems/invert binary tree/description/] 思路:题目要求交换二叉树的左右叶子,直接遍历全树,交换左右节点即可 代码 讨论区[https://leetcode.com/problems/invert bi
阅读全文
摘要:题目:[https://leetcode cn.com/problems/minimum depth of binary tree/description/] 思路:逐层遍历,当某层有子节点时,当前层即是最小深度 代码: 讨论区[https://leetcode.com/problems/minim
阅读全文
摘要:题目:[https://leetcode cn.com/problems/maximum depth of binary tree/description/] 思路:遍历二叉树,并记录访问节点的深度,与已知最大节点比较。返回最大值 讨论区[https://leetcode.com/problems/
阅读全文
摘要:题目:[https://leetcode cn.com/problems/valid anagram/description/] 思路:分别对于字母出现次数进行统计,完全相同的即为异位词
阅读全文
摘要:题目:[https://leetcode cn.com/problems/intersection of two arrays/description/] 思路:统计每个数定出现次数,输出出现两次 代码:
阅读全文
摘要:题目:[https://leetcode cn.com/problems/binary search/description/] 思路:实现二分查找,对于有序序列的一组查找方式。通过将目标值与中值进行比较,不断缩小范围,找到值到方法。 代码: c++ class Solution { public:
阅读全文
摘要:题目:[https://leetcode cn.com/problems/positions of large groups/description/] 思路:题目要求统计出现3次以上字母分组,返回其首尾值的集合。通过观察,不断比较前后字母是否相等并计数,返回出现3次以上的序列值 代码 讨论区[ht
阅读全文
摘要:题目:[https://leetcode cn.com/problems/1 bit and 2 bit characters/description/] 思路:编码问题。给定一个串二进制位,判断最后一个字符是1比特字符还是2比特字符。考虑实际解码过程,01序列由0,11,10构成。遍历序列,如果第
阅读全文
摘要:题目:[https://leetcode cn.com/problems/image smoother/description/] 思路:一道直接模拟题目,计算图片的灰度,注意边界控制。 代码: 讨论区[https://leetcode.com/problems/image smoother/dis
阅读全文
摘要:题目:[https://leetcode cn.com/problems/find all numbers disappeared in an array/description/] 思路:标记法,由于所有元素当范围在[1,n]之间,所以考虑标记出现过当元素,最后没有出现过当元素即为所求。 代码:
阅读全文

浙公网安备 33010602011771号