LeetCode | 179. 最大数
我的Bilibili频道:香芋派Taro我的个人博客:taropie0224.github.io(阅读体验更佳)我的公众号:香芋派的烘焙坊我的音频技术交流群:1136403177我的个人微信:JazzyTaroPie
https://leetcode-cn.com/problems/largest-number/
题解1234567891011121314151617181920212223242526class Solution{public: string largestNumber(vector<int> &nums) { sort(nums.begin(), nums.end(), [](int i, int j) { string istr = to_string(i); string jstr = to_string(j); return istr+jstr > jstr+istr; } ...
LeetCode | 122. 路径总和
我的Bilibili频道:香芋派Taro我的个人博客:taropie0224.github.io(阅读体验更佳)我的公众号:香芋派的烘焙坊我的音频技术交流群:1136403177我的个人微信:JazzyTaroPie
https://leetcode-cn.com/problems/path-sum/
题解12345678910111213141516class Solution{public: bool hasPathSum(TreeNode *root, int targetSum) { if (root == nullptr) { return false; } if (targetSum == root->val && root->left == nullptr && root->right == nullptr) { return true; ...
LeetCode | 101. 对称二叉树
我的Bilibili频道:香芋派Taro我的个人博客:taropie0224.github.io(阅读体验更佳)我的公众号:香芋派的烘焙坊我的音频技术交流群:1136403177我的个人微信:JazzyTaroPie
https://leetcode-cn.com/problems/symmetric-tree/
题解1234567891011121314151617181920class Solution{public: bool isSymmetric(TreeNode *root) { if (!root) return true; return dfs(root->left, root->right); } bool dfs(TreeNode *p, TreeNode *q) { if (!p && !q) return true; if (!p || !q) ...
LeetCode | 56. 合并区间
我的Bilibili频道:香芋派Taro我的个人博客:taropie0224.github.io(阅读体验更佳)我的公众号:香芋派的烘焙坊我的音频技术交流群:1136403177我的个人微信:JazzyTaroPie
https://leetcode-cn.com/problems/merge-intervals/
题解1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556class Solution{public: vector<vector<int> > merge(vector<vector<int> > &intervals) { if (intervals.size() == 0) { return {}; } if ...
LeetCode | 54. 螺旋矩阵
我的Bilibili频道:香芋派Taro我的个人博客:taropie0224.github.io(阅读体验更佳)我的公众号:香芋派的烘焙坊我的音频技术交流群:1136403177我的个人微信:JazzyTaroPie
https://leetcode-cn.com/problems/spiral-matrix/
题解12345678910111213141516171819202122232425262728293031323334353637383940414243class Solution{public: vector<int> spiralOrder(vector<vector<int> > &matrix) { //行列数 int m = matrix.size(); int n = matrix[0].size(); //上下左右标记 int top = 0; int down = m - 1; ...
LeetCode | 876. 链表的中间节点
我的Bilibili频道:香芋派Taro
我的个人博客:taropie0224.github.io(阅读体验更佳)我的公众号:香芋派的烘焙坊我的音频技术交流群:1136403177我的个人微信:JazzyTaroPie
https://leetcode.cn/problems/middle-of-the-linked-list/
题解123456789101112131415class Solution{public: ListNode *middleNode(ListNode *head) { ListNode *slow = head; ListNode *fast = head; while (fast != NULL && fast->next != NULL) { slow = slow->next; fast = fast->next->next; } ...
LeetCode | 674. 最长连续递增序列
我的Bilibili频道:香芋派Taro我的个人博客:taropie0224.github.io(阅读体验更佳)我的公众号:香芋派的烘焙坊我的音频技术交流群:1136403177我的个人微信:JazzyTaroPie
https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/
题解123456789101112131415161718class Solution{public: int findLengthOfLCIS(vector<int> &nums) { int ans = 0, start = 0; int n = nums.size(); for (int i = 0; i < n; i++) { if (i > 0 && nums[i - 1] >= nums[i]) { ...
LeetCode | 628. 三个数的最大乘积
我的Bilibili频道:香芋派Taro我的个人博客:taropie0224.github.io(阅读体验更佳)我的公众号:香芋派的烘焙坊我的音频技术交流群:1136403177我的个人微信:JazzyTaroPie
https://leetcode-cn.com/problems/maximum-product-of-three-numbers/
题解12345678910111213class Solution{public: int maximumProduct(vector<int> &nums) { sort(nums.begin(), nums.end()); int n = nums.size() - 1; int max1 = nums[0] * nums[1] * nums[n]; int max2 = nums[n] * nums[n - 1] * nums[n - 2]; int res = max(max1, max2); ...
LeetCode | 415. 字符串相加
我的Bilibili频道:香芋派Taro我的个人博客:taropie0224.github.io(阅读体验更佳)我的公众号:香芋派的烘焙坊我的音频技术交流群:1136403177我的个人微信:JazzyTaroPie
https://leetcode-cn.com/problems/add-strings/
题解123456789101112131415161718192021222324252627282930313233343536373839class Solution{public: string addStrings(string num1, string num2) { int isAdvance = 0; string res = ""; int n1 = num1.length() - 1, n2 = num2.length() - 1; int Max = max(n1, n2); while (Max >= 0 || isAdvance ...
LeetCode | 283. 移动零
我的Bilibili频道:香芋派Taro我的个人博客:taropie0224.github.io(阅读体验更佳)我的公众号:香芋派的烘焙坊我的音频技术交流群:1136403177我的个人微信:JazzyTaroPie
https://leetcode-cn.com/problems/move-zeroes/
题解123456789101112131415161718class Solution{public: void moveZeroes(vector<int> &nums) { int n = nums.size(); int left = 0, right = 0; while (right < n) { if (nums[right]) { swap(nums[left], nums[right]); left++; ...