刷题记录
wwwsctvcom
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode1143. 最长公共子序列
【代码】LeetCode1143. 最长公共子序列。原创 2022-09-29 00:47:18 · 369 阅读 · 0 评论 -
LeetCode142. 环形链表 II
【代码】LeetCode142. 环形链表 II。原创 2022-09-28 22:48:34 · 438 阅读 · 0 评论 -
LeetCode48.旋转图像
【代码】LeetCode48.旋转图像。原创 2022-09-28 21:34:15 · 357 阅读 · 0 评论 -
LeetCode318:最大单词长度乘积
最大单词长度乘积原创 2022-09-17 20:28:54 · 208 阅读 · 0 评论 -
LeetCode12:整数转罗马数字
整数转罗马数字原创 2022-09-17 14:12:13 · 193 阅读 · 0 评论 -
LeetCode2109:向字符串添加空格
向字符串添加空格原创 2022-09-16 23:04:48 · 224 阅读 · 0 评论 -
LeetCode1910:删除一个字符串中所有出现的给定子字符串
删除一个字符串中所有出现的给定子字符串原创 2022-09-16 00:14:32 · 241 阅读 · 0 评论 -
LeetCode152:翻转字符串里面的单词
题解和题目链接 力扣 class Solution { public: string reverseWords(string s) { string ans; int i = s.size() - 1; while (i >= 0) { int c = 0; while (i >= 0 && s[i] == ' ') i--; whil...原创 2021-12-27 00:14:37 · 249 阅读 · 0 评论 -
LeetCode394:字符串解码
题解: class Solution { public: string decodeString(string s) { string res = ""; stack<string> strs; stack<int> nums; int num = 0; int n = s.size(); for (int i = 0; i < n; i++) { ...原创 2021-12-26 23:25:03 · 331 阅读 · 0 评论 -
LeetCode43:字符串相乘
解题思路: 代码 class Solution { public: string multiply(string num1, string num2) { if (num1 == "0" || num2 == "0") { return "0"; } string ans; int m = num1.size(), n = num2.size(); // 依次用num2的值乘n..原创 2021-12-26 01:22:01 · 283 阅读 · 0 评论 -
LeetCode415:字符串相加
class Solution { public: string addStrings(string num1, string num2) { int i = num1.size()-1, j = num2.size()-1, add = 0; string ans; while (i >= 0 || j >= 0 || add != 0) { int x = i >= 0 ? num1.at(i) ...原创 2021-12-26 00:46:37 · 198 阅读 · 0 评论 -
LeetCode22题:括号生成
题解: class Solution { public: vector<string> generateParenthesis(int n) { vector<string> vec; string str = ""; dfs(vec, str, n, n); return vec; } void dfs(vector<string> &vec, const str...原创 2021-12-25 20:39:50 · 248 阅读 · 0 评论 -
工作安排(c++)
题目:https://www.nowcoder.com/questionTerminal/937d8a6766a5488d958d55ddf3ec5cef?f=discussion #include<iostream> #include<vector> #include <algorithm> using namespace std; int main() { int n, a, b; cin >> n; vector<vector<in原创 2021-07-20 17:42:06 · 426 阅读 · 0 评论 -
LeetCode509-斐波那契数列
题解: class Solution { public: int fib(int n) { if (n == 0) return 0; if (n == 1 || n == 2) return 1; vector<int> dp(n+1, 0); dp[1] = dp[2] = 1; for (int i = 3; i <= n; i++) { dp[i] = dp[i...原创 2021-07-17 01:37:28 · 148 阅读 · 0 评论 -
518.LeetCode零钱兑换(2)
题目描述: 采用方法:动态规划 初始dp[0] = 1,其他值0 代码: coins = [1, 2, 5] amount = 5 #dp[i]:组成面值i的方法的数量 dp = [0] * (amount + 1) dp[0] = 1 for c in coins: for i in range(c, amount + 1): dp[i] += dp[i ...原创 2019-08-11 14:24:08 · 135 阅读 · 0 评论 -
牛客:最长公共子序列
题目描述:https://www.nowcoder.com/questionTerminal/c996bbb77dd447d681ec6907ccfb488a 实现代码: #最长公共子序列; s1 = 'BDCABA' s2 = 'ABCBDAB' n1 = len(s1) n2 = len(s2) dp = [[0] * (n1 + 1)] * (n2 + 1) for i ...原创 2019-08-11 22:44:13 · 739 阅读 · 0 评论 -
leetcode547: Friend Circles
题目描述: 参考地址: https://www.cnblogs.com/grandyang/p/6686983.html https://blog.youkuaiyun.com/niushuai666/article/details/6662911 有个班级,里面有N个学生,他们之中有些是朋友有些不是,比如如果A是B的朋友,B是C的朋友,那么A就是C的间接朋友,我们定义所谓的朋友圈就是由直系和间接朋友...原创 2019-08-26 10:15:35 · 369 阅读 · 0 评论 -
leetcode323:无向图中的连通区域的个数
题目描述: 参考博客:https://www.cnblogs.com/grandyang/p/5166356.html 题目地址:https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/ 代码实现: #方法一:并查集 n = 5 v = [[0, 1], [1, 2]...原创 2019-08-27 10:57:16 · 1954 阅读 · 0 评论 -
数组的一些相关题目
参考博客:https://www.jianshu.com/p/ef07ef2aa8d1 代码实现(python): ''' 数组问题 ''' #打印转圈数组 #nums = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] def rotate_print(nums): ''' nums = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]...原创 2019-09-02 10:58:11 · 201 阅读 · 0 评论 -
322.LeetCode硬币找零
题目描述: 初始化:inf,dp[0] = 0 采用方法:动态规划 参考地址:https://www.cnblogs.com/grandyang/p/5138186.html coins = [1, 2, 5] amount = 11 #dp[i]:面值为i时需要的最少硬币数量 dp = [float("inf")] * (amount + 1) dp[0] = 0 for i i...原创 2019-08-11 10:41:22 · 192 阅读 · 0 评论
分享