
leetcode
Cubbyz
在这里的我们素不相识,却都在为了自己的梦而努力 ❤
展开
-
leetcode 13. 罗马数字转整数
13. 罗马数字转整数class Solution {public: int romanToInt(string s) { unordered_map<char, int> hash; hash['I'] = 1, hash['V'] = 5; hash['X'] = 10, hash['L'] = 50; hash['C'] = 100, hash['D'] = 500; hash['M'] =原创 2022-03-27 16:22:37 · 402 阅读 · 0 评论 -
leetcode 12. 整数转罗马数字
12. 整数转罗马数字cpp code:class Solution {public: string intToRoman(int num) { int values[] = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; string unit[] = {原创 2022-03-27 15:47:57 · 132 阅读 · 0 评论 -
11. 盛最多水的容器
leetcode11盛水最多的容器class Solution {public: int maxArea(vector<int>& height) { int ans = 0 ; for (int i = 0, j = height.size() - 1; i < j;) { ans = max(ans, min(height[i],height[j]) * (j - i));原创 2022-03-27 14:28:27 · 99 阅读 · 0 评论 -
leetcode23.括号生成cpp
contentcodeclass Solution {public: vector<string> ans; vector<string> generateParenthesis(int n) { dfs(n, 0, 0, ""); return ans; } void dfs(int n, int lc, int rc, string sec) { if (lc == n &&a原创 2022-03-27 10:03:31 · 104 阅读 · 0 评论 -
leetcode20.有序的括号
class Solution {public: bool isValid(string s) { stack<char> stk; for (char c : s) { if (c == '{' || c == '(' || c == '[') { stk.push(c); } else { .原创 2022-03-27 10:01:50 · 121 阅读 · 0 评论 -
leetcode21合并两个有序链表 Cpp
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next.原创 2022-03-27 09:53:53 · 372 阅读 · 0 评论