会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Figure at a Window
管理
2023年1月2日
剑指offer面试题45. 把数组排成最小的数
摘要: 题意 把数组排成最小的数 方法 排序 代码 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:04 Figure_at_a_Window
阅读(14)
评论(0)
推荐(0)
2022年12月12日
LeetCode962. Maximum Width Ramp
摘要: 题意 给一个序列,求其中最大的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
阅读(16)
评论(0)
推荐(0)
2022年12月5日
LeetCode397. Integer Replacement
摘要: 题意 一个数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
阅读(28)
评论(0)
推荐(0)
2022年11月28日
LeetCode347. Top K Frequent Elements
摘要: 题意 给一个序列, 输出其前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
阅读(25)
评论(0)
推荐(0)
2022年11月21日
LeetCode199. Binary Tree Right Side View
摘要: 题意 实现二叉树的右视图 方法 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
阅读(22)
评论(0)
推荐(0)
2022年11月14日
LeetCode300. Longest Increasing Subsequence
摘要: 题意 求数组最长递增子序列的长度 方法 单调数组 代码 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:09 Figure_at_a_Window
阅读(16)
评论(0)
推荐(0)
2022年11月7日
LeetCode40. 组合总和 II
摘要: 题意 给一个数组和target, 找出数组中所有和为target的组合 方法 DFS 代码 class Solution { private: vector<vector<int>> res; vector<int> tmp; public: int getNextNumberIndex(vecto
阅读全文
posted @ 2022-11-07 18:35 Figure_at_a_Window
阅读(19)
评论(0)
推荐(0)
2022年10月30日
LeetCode15. 三数之和
摘要: #题意 找出数组中三个和为0的数字 #方法 哈希表 #代码 class Solution { public: vector<vector<int>> threeSum(vector<int>& nums) { vector<vector<int>> result; sort(nums.begin()
阅读全文
posted @ 2022-10-30 23:02 Figure_at_a_Window
阅读(26)
评论(0)
推荐(0)
2022年10月24日
LeetCode17. Letter Combinations of a Phone Number
摘要: 题意 根据数字得到号码组合 方法 模拟 代码 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
阅读(28)
评论(0)
推荐(0)
2022年10月17日
LeetCode877. Stone Game
摘要: 题意 alice和bob又开始了 方法 先手稳赢 代码 class Solution { public: bool stoneGame(vector<int>& piles) { return true; } };
阅读全文
posted @ 2022-10-17 20:00 Figure_at_a_Window
阅读(14)
评论(0)
推荐(0)
下一页