![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
Risotto_nero
这个作者很懒,什么都没留下…
展开
-
leetcode到达终点
780. 到达终点 class Solution { public: bool reachingPoints(int sx, int sy, int tx, int ty) { while(tx>sx&&ty>sy&& tx!=ty){ if(ty>tx){ ty%=tx; }else{ tx%=ty;原创 2022-04-10 00:35:12 · 41 阅读 · 0 评论 -
leetcodeN 叉树的层序遍历
429. N 叉树的层序遍历 bfs,记录每一层最后的结点,方法来自数据结构的六度空间 /* // Definition for a Node. class Node { public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; } Node(int _val, vector<Node*> _children) {原创 2022-04-09 10:31:04 · 813 阅读 · 0 评论 -
力扣二进制表示中质数个计算置位
762. 二进制表示中质数个计算置位 这个简单题包含多个点: 把一个数变成二进制 统计二进制数1的个数 判断是否是质数 统计二进制1的个数 191. 位1的个数 class Solution { public: int hammingWeight(uint32_t n) { int ret = 0; for (int i = 0; i < 32; i++) { if (n & (1 << i)) {原创 2022-04-09 10:27:14 · 65 阅读 · 0 评论 -
172.阶乘后的零
172. 阶乘后的零 题目要求给出一个数,计算这个数的阶乘后的尾随零。 n<=10^4 因此直接算会超时。 尾随0的个数就是因子 10的个数,10=2*5,转换成求 n! 中质因子 2 的个数和质因子 5的个数的较小值。质因子是能整除被除数的质数。 经证明,质因子2的个数比质因子5的个数多,因此仅考虑质因子2的个数。 而 n! 中质因子 5 的个数等于 [1,n] 的每个数的质因子 5 的个数之和,我们可以通过遍历 [1,n] 的所有 5 的倍数求出。 class Solution { public原创 2022-03-26 23:08:57 · 44 阅读 · 0 评论 -
125. 验证回文串
125. 验证回文串 输入: “A man, a plan, a canal: Panama” 输出: true 解释:“amanaplanacanalpanama” 是回文串 int isalnum ( int c );判断一个字符是否是字母或数字 tolower() c++ 反向迭代器 .rbegin():指向容器最后一个元素的前一个位置 .rend():指向容器第一个元素 begin():指向容器第一个元素 end():指向容器最后一个元素的前一个位置 ++是向前遍历,--是向后遍历 假设一段字原创 2022-01-15 16:21:11 · 157 阅读 · 0 评论 -
120. Triangle-leetcode
120. Triangle Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1原创 2021-12-25 16:45:17 · 231 阅读 · 0 评论 -
97.交错字符串-leetcode
97. 交错字符串 这道题我太冲动了,没有多想就用双指针,结果试到82个样例才知道错误。然后用了最容易想到的递归,写了两小时,最终因为边界条件太难判断而且容易超时而放弃,浪费了一个下午的时间,因为这道题整天无所作为,无精打采,并且只是leetcode的一道中等题。算法这条路,虽然我想走,但很庆幸没有走,但是我还是想走,路漫漫其修远兮。 双指针为什么不行 遇到这种情况 aabcc dbbca aadbcbbcac 当试完aad的字符串之后,b可以选aabcc的b,也可以选择dbbca的b,选后者是失败的,选原创 2021-12-25 16:34:51 · 238 阅读 · 0 评论 -
131.Palindrome Partitioning-leetcode
131. leetcode分割回文串 Palindrome Partitioning 题目链接 Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. A palindrome string is a string that reads the same backward as forw原创 2021-12-25 16:25:36 · 311 阅读 · 0 评论