摘要: #include <iostream> #include <vector> #include <algorithm> // for std::swap // 冒泡排序 void bubbleSort(std::vector<int>& arr) { int n = arr.size(); for ( 阅读全文
posted @ 2026-07-15 20:12 Acyclonepl 阅读(5) 评论(0) 推荐(0)
摘要: class Solution { public: int singleNonDuplicate(vector<int>& nums) { /*r 初始化为 k,它表示可能的第一个异常配对索引的上界。 如果所有配对都正常,那么第一个异常配对并不存在,此时答案就是最后一个单独元素, 可以认为“虚拟”的异 阅读全文
posted @ 2026-07-15 19:01 Acyclonepl 阅读(3) 评论(0) 推荐(0)
摘要: class Solution { public: int findMin(vector<int>& nums) { int l = 0, r = nums.size() - 1; int min = 10000; while (l <= r) { int mid = l + (r - l) / 2; 阅读全文
posted @ 2026-07-14 22:36 Acyclonepl 阅读(4) 评论(0) 推荐(0)
摘要: class Solution { public: bool search(vector<int>& nums, int target) { int l = 0, r = nums.size() - 1; while (l <= r) { int mid = (l+r)/2; if (nums[mid 阅读全文
posted @ 2026-07-14 21:29 Acyclonepl 阅读(3) 评论(0) 推荐(0)
摘要: class Solution { public: vector<int> searchRange(vector<int>& nums, int target) { if (nums.empty()) return vector<int>{-1, -1}; int lower = lower_boun 阅读全文
posted @ 2026-07-14 16:26 Acyclonepl 阅读(2) 评论(0) 推荐(0)
摘要: class Solution { public: int mySqrt(int a) { // 1. 边界处理:0 的平方根还是 0 if(a==0) return a; int l=1,r=a,mid,sqrt; // 2. 初始化指针 // l (左指针) = 1,因为 a>0,答案至少是 1 阅读全文
posted @ 2026-07-14 14:51 Acyclonepl 阅读(1) 评论(0) 推荐(0)
摘要: class Solution { public: string findLongestWord(string s, vector<string>& dictionary) { sort(dictionary.begin(),dictionary.end(),[&](string &a,string 阅读全文
posted @ 2026-07-13 20:41 Acyclonepl 阅读(1) 评论(0) 推荐(0)
摘要: class Solution { public: bool check(const string &s,int l,int r){ //判断字符串是否为回文串 for(int i=l,j=r;i<j;++i,--j){ if(s[i]!=s[j]){ return false; } } return 阅读全文
posted @ 2026-07-13 16:21 Acyclonepl 阅读(3) 评论(0) 推荐(0)
摘要: class Solution { public: bool judgeSquareSum(int c) { int l=0,r=sqrt(c); while(l<=r){//注意l可以等于r if(l*l==c-r*r){ return true; } if(l*l<c-r*r){ l++;//小于 阅读全文
posted @ 2026-07-13 16:01 Acyclonepl 阅读(2) 评论(0) 推荐(0)
摘要: class Solution { public: string minWindow(string s, string t) { vector<int> chars(128); // 字符本身作为键k,它们的个数作为值v vector<bool> flag(128, false); // 字符本身作为 阅读全文
posted @ 2026-07-11 18:06 Acyclonepl 阅读(2) 评论(0) 推荐(0)