llllmz

导航

上一页 1 2 3 4 5 6 7 8 9 ··· 35 下一页

2024年9月4日

34. 在排序数组中查找元素的第一个和最后一个位置

摘要: 这题还蛮有意思的,看了下解析,分成两部分分开来求解。 左右边界都是普通的二分查找算法,重点就是当等于的时候的处理,左边界函数等于目标值的时候,要记录当前mid的值作为边界,同时区间要向左移。 反过来,右边界的话,区间要向右移动。记得记录相等时候的mid值,最后一次相等记录的值也就是这个边界值。 cl 阅读全文

posted @ 2024-09-04 17:43 神奇的萝卜丝 阅读(15) 评论(0) 推荐(0)

704. 二分查找 C++

摘要: class Solution { public: int search(vector<int>& nums, int target) { int head = 0, tail = nums.size() - 1; while(head <= tail){ int mid = head + (tail 阅读全文

posted @ 2024-09-04 15:49 神奇的萝卜丝 阅读(19) 评论(0) 推荐(0)

2024年3月22日

2605. 从两个数字数组里生成最小数字c

摘要: int minNumber(int* nums1, int nums1Size, int* nums2, int nums2Size) { int min=INT_MAX; for(int i=0;i<nums1Size;i++){ int sum=0; for(int j=0;j<nums2Siz 阅读全文

posted @ 2024-03-22 11:08 神奇的萝卜丝 阅读(11) 评论(0) 推荐(0)

2367. 算术三元组的数目c

摘要: int count; void dfs(int* nums,int numsSize,int diff,int index,int pre,int nowcount){ if(index>numsSize || nowcount>3) return; if(index==numsSize && no 阅读全文

posted @ 2024-03-22 10:53 神奇的萝卜丝 阅读(9) 评论(0) 推荐(0)

2652. 倍数求和c

摘要: int sumOfMultiples(int n){ int* dp=(int*)malloc(sizeof(int)*(n+4)); dp[1]=0,dp[2]=0; for(int i=3;i<=n;i++){ if(i%3==0 || i%5==0 || i%7==0 ){ dp[i]=dp[ 阅读全文

posted @ 2024-03-22 10:29 神奇的萝卜丝 阅读(36) 评论(0) 推荐(0)

2798. 满足目标工作时长的员工数目c

摘要: int numberOfEmployeesWhoMetTarget(int* hours, int hoursSize, int target){ int count=0; for(int i=0;i<hoursSize;i++){ if(hours[i] >= target) count++; } 阅读全文

posted @ 2024-03-22 10:24 神奇的萝卜丝 阅读(12) 评论(0) 推荐(0)

2917. 找出数组中的 K-or 值c

摘要: int findKOr(int* nums, int numsSize, int k) { if(k>numsSize) return 0; int sum=0; for(int i=0;i<31;i++){ int count=0; for(int j=0;j<numsSize;j++){ int 阅读全文

posted @ 2024-03-22 10:22 神奇的萝卜丝 阅读(12) 评论(0) 推荐(0)

2465. 不同的平均值数目c

摘要: int cmp(const void* a,const void* b){ return *(int*)a-*(int*)b; } int distinctAverages(int* nums, int numsSize) { if(numsSize <=2) return 1; qsort(num 阅读全文

posted @ 2024-03-22 10:08 神奇的萝卜丝 阅读(10) 评论(0) 推荐(0)

2024年3月21日

90. 子集 IIc

摘要: /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array a 阅读全文

posted @ 2024-03-21 20:55 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0)

125. 验证回文串c

摘要: bool judge(char c){ if(c>='a'&& c<='z' || c>='A' && c<='Z' || c>='0' && c<='9' ) return true; return false; } bool isPalindrome(char* s) { int n=strle 阅读全文

posted @ 2024-03-21 20:38 神奇的萝卜丝 阅读(24) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 8 9 ··· 35 下一页