上一页 1 2 3 4 5 6 7 ··· 22 下一页

2024年11月11日

摘要: 1 class Solution { 2 public: 3 int minCost(int n, vector<int>& cuts) { 4 int m = cuts.size(); 5 sort(cuts.begin(), cuts.end()); 6 cuts.insert(cuts.beg 阅读全文
posted @ 2024-11-11 10:18 greenofyu 阅读(27) 评论(0) 推荐(0)

2024年11月10日

摘要: 要求O(logn)的复杂度基本就是二分。 分析序列1,1,2,2,3,4,4,5,5 (0,1),(2,3),(5,6),(7,8)各自成对。 0,1 10,11 101,110 111,1000 可以观察出目标的左边可用^异或找出成对的,右边则不行,所以可以据此来二分。 1 class Solut 阅读全文
posted @ 2024-11-10 11:54 greenofyu 阅读(26) 评论(0) 推荐(0)

2024年11月9日

摘要: 模拟题,需要找到之后需要判定一下边界,别越界了。 1 class NeighborSum { 2 private: 3 int n; 4 vector<vector<int>> grid; 5 vector<vector<int>> adj={{-1,0},{0,1},{1,0},{0,-1}}; 阅读全文
posted @ 2024-11-09 19:46 greenofyu 阅读(17) 评论(0) 推荐(0)

2024年11月8日

摘要: 1 class Solution { 2 public: 3 bool canReachCorner(int xCorner, int yCorner, vector<vector<int>>& circles) { 4 vector<bool> visited(circles.size(), fa 阅读全文
posted @ 2024-11-08 15:36 greenofyu 阅读(27) 评论(0) 推荐(0)

2024年11月7日

摘要: 遍历nums数组,记录当前已有多少按1递增的元素。 1 class Solution { 2 public: 3 vector<int> resultsArray(vector<int>& nums, int k) { 4 int cnt=0; 5 int n=nums.size(); 6 vect 阅读全文
posted @ 2024-11-07 12:11 greenofyu 阅读(17) 评论(0) 推荐(0)

2024年11月6日

摘要: 1 class Solution { 2 public: 3 vector<int> resultsArray(vector<int>& nums, int k) { 4 int n = nums.size(); 5 int cnt = 0; 6 vector<int> ans(n - k + 1, 阅读全文
posted @ 2024-11-06 21:21 greenofyu 阅读(31) 评论(0) 推荐(0)

2024年11月5日

摘要: 模拟题。 1 class Solution { 2 public: 3 string losingPlayer(int x, int y) { 4 bool flag=false; 5 while(x>=1&&y>=4){ 6 flag=!flag; 7 x-=1,y-=4; 8 } 9 if(fl 阅读全文
posted @ 2024-11-05 10:21 greenofyu 阅读(20) 评论(0) 推荐(0)

2024年11月4日

摘要: 使用sqrt函数模拟。 1 typedef long long LL; 2 class Solution { 3 public: 4 bool judgeSquareSum(int c) { 5 for(LL i=0;i*i<=c;i++){ 6 LL a_2=i*i; 7 LL b_2=c-a_2 阅读全文
posted @ 2024-11-04 10:07 greenofyu 阅读(27) 评论(0) 推荐(0)

2024年11月3日

摘要: 1 class Solution { 2 public: 3 map<vector<int>, int> memo; 4 5 int shoppingOffers(vector<int>& price, vector<vector<int>>& special, vector<int>& needs 阅读全文
posted @ 2024-11-03 13:47 greenofyu 阅读(34) 评论(0) 推荐(0)

2024年11月2日

摘要: 模拟题,但是要注意按位与操作和比较运算符的优先级,比较运算符优先级更高,所以t1,t2这样写,不然就得加括号。 1 class Solution { 2 public: 3 int minChanges(int n, int k) { 4 int res=0; 5 while(n&&k){ 6 in 阅读全文
posted @ 2024-11-02 12:09 greenofyu 阅读(22) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 ··· 22 下一页