摘要: 题意 把数组排成最小的数 方法 排序 代码 class Solution { public: static bool cmp(int a, int b){ string as = to_string(a), bs = to_string(b); return as + bs < bs + as; } 阅读全文
posted @ 2023-01-02 21:05 Figure_at_a_Window 阅读(9) 评论(0) 推荐(0) 编辑
摘要: 题意 给一个序列,求其中最大的j-i, 满足i < j且num[i] <= nums[j] 方法 单调栈 代码 class Solution { public: int maxWidthRamp(vector<int>& A) { stack<int> s; int n=A.size(); int 阅读全文
posted @ 2022-12-12 21:59 Figure_at_a_Window 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 题意 一个数n, 若为偶数, 则除2, 若为奇数, 则加减1; 求其最终为1, 需要几步 方法 位运算 代码 class Solution { public: int integerReplacement(int n) { if(n==1) return 0; int result=0; while 阅读全文
posted @ 2022-12-05 20:28 Figure_at_a_Window 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 题意 给一个序列, 输出其前K个出现频次的数字 方法 优先队列 代码 class Solution { public: struct node{ int val;//值 int cnt;//出现次数 node():cnt(0){} node(int aval , int acnt):val(aval 阅读全文
posted @ 2022-11-28 19:14 Figure_at_a_Window 阅读(13) 评论(0) 推荐(0) 编辑
摘要: 题意 实现二叉树的右视图 方法 BFS 代码 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val 阅读全文
posted @ 2022-11-21 20:09 Figure_at_a_Window 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 题意 求数组最长递增子序列的长度 方法 单调数组 代码 class Solution { public: int lengthOfLIS(vector<int>& nums) { vector <int> a(nums.size()); a[0]=1; for(int i=1;i<nums.size 阅读全文
posted @ 2022-11-14 20:10 Figure_at_a_Window 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 题意 给一个数组和target, 找出数组中所有和为target的组合 方法 DFS 代码 class Solution { private: vector<vector<int>> res; vector<int> tmp; public: int getNextNumberIndex(vecto 阅读全文
posted @ 2022-11-07 18:36 Figure_at_a_Window 阅读(14) 评论(0) 推荐(0) 编辑
摘要: #题意 找出数组中三个和为0的数字 #方法 哈希表 #代码 class Solution { public: vector<vector<int>> threeSum(vector<int>& nums) { vector<vector<int>> result; sort(nums.begin() 阅读全文
posted @ 2022-10-30 23:03 Figure_at_a_Window 阅读(17) 评论(0) 推荐(0) 编辑
摘要: 题意 根据数字得到号码组合 方法 模拟 代码 class Solution { public: vector<string> letterCombinations(string digits) { int len[]={0,0,3,3,3,3,3,4,3,4},length=digits.lengt 阅读全文
posted @ 2022-10-24 21:06 Figure_at_a_Window 阅读(18) 评论(0) 推荐(0) 编辑
摘要: 题意 alice和bob又开始了 方法 先手稳赢 代码 class Solution { public: bool stoneGame(vector<int>& piles) { return true; } }; 阅读全文
posted @ 2022-10-17 20:01 Figure_at_a_Window 阅读(7) 评论(0) 推荐(0) 编辑