当前位置: 首页 > news >正文

刚做的网站搜索不到aso优化吧

刚做的网站搜索不到,aso优化吧,提供手机网站制作公司,网站建设套餐内容寻找两个正序数组的中位数 仅供学习 题目 算法时间复杂度 二分查找算法,时间复杂度为 O(log(min(m, n))),其中 m 和 n 分别是两个数组的长度。 子函数 查找两个数字的最大值 int max(int a, int b) {return a > b ? a : b; }查找两个数字的最小…

寻找两个正序数组的中位数

仅供学习

题目

在这里插入图片描述


算法时间复杂度

二分查找算法,时间复杂度为 O(log(min(m, n))),其中 m 和 n 分别是两个数组的长度。

子函数

查找两个数字的最大值

int max(int a, int b) {return a > b ? a : b;
}

查找两个数字的最小值

int min(int a, int b) {return a < b ? a : b;
}

findMedianSortedArrays

double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size) {// Ensure nums1 is the smaller arrayif (nums1Size > nums2Size) {return findMedianSortedArrays(nums2, nums2Size, nums1, nums1Size);}int x = nums1Size;int y = nums2Size;int low = 0;int high = x;while (low <= high) {int partitionX = (low + high) / 2;int partitionY = (x + y + 1) / 2 - partitionX;int maxX = (partitionX == 0) ? INT_MIN : nums1[partitionX - 1];int minX = (partitionX == x) ? INT_MAX : nums1[partitionX];int maxY = (partitionY == 0) ? INT_MIN : nums2[partitionY - 1];int minY = (partitionY == y) ? INT_MAX : nums2[partitionY];if (maxX <= minY && maxY <= minX) {// We have partitioned array at the correct place// Now we get max of left elements and min of right elements to get the median in case of even length combined array sizeif ((x + y) % 2 == 0) {return ((double)max(maxX, maxY) + min(minX, minY)) / 2;} else {return (double)max(maxX, maxY);}} else if (maxX > minY) { // we are too far on the right side for partitionX. Go on left side.high = partitionX - 1;} else { // we are too far on the left side for partitionX. Go on right side.low = partitionX + 1;}}// If we reach here, it means the arrays are not sortedfprintf(stderr, "Input arrays are not sorted or there is some other error.\n");return -1;
}

说明

  • 该代码实现了一个查找两个正序数组中位数的算法,使用了二分查找法来优化时间复杂度。
  • findMedianSortedArrays 函数首先确保第一个数组(nums1)是较小的一个,这样可以减小搜索范围。
  • 在 while 循环中,通过二分查找确定两个数组的分割点,使得分割后的左半部分和右半部分元素数量接近。
  • 根据分割点计算最大左边元素和最小右边元素,进而确定中位数。
  • 主函数通过示例数据验证了算法的正确性。
http://www.fp688.cn/news/162205.html

相关文章:

  • 网站政府网站集约化建设盐城seo营销
  • 网站打不开怎么办东莞关键词优化软件
  • 自己做的网站如何制作后台淘宝流量平台
  • isp网站接入做哪些业务保定关键词排名推广
  • 网站制作地点软文推广文章案例
  • 网站谁做的比较好发外链平台
  • 注册网站商标多少钱最近几天新闻大事
  • html网站建设app推广接单渠道
  • 网站的营销特点成人短期培训能学什么
  • 做网站的公司北京有哪些关键词英文
  • 微信做模板下载网站有哪些内容电商培训机构有哪些?哪家比较好
  • 宣城 网站建设快速提高关键词排名的软件
  • 做网站维护要学些什么全面落实疫情防控优化措施
  • app开发的网站最新的全国疫情
  • 开网站做销售提高工作效率英语
  • 新网做网站流程怎么做好网站方式推广
  • 潍坊网站建设熊掌号网络舆情管理
  • 身份证和手机做验证码注册网站免费crm
  • 宁波网站建设用什么软件网站推广seo设置
  • 广州公司注册名称核名查询系统网页版优化排名
  • 网站二维码怎么做百度收录入口
  • 检察机关门户网站建设自查报告建网站公司
  • 有赞小程序开发平台北京网站seo优化推广
  • 电子商务网站建设与管理课后题答案新手如何学seo
  • 上海企业网站建设服务网站优化有哪些类型
  • 济南网站建设云华互动网上怎么免费推广
  • 商丘做网站优化seo人才招聘
  • 免费稳定的网站空间百度关键词怎么做排名
  • 上海做网站的公司官网东莞seo公司
  • 房县网站建设互联网app推广具体怎么做