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

一个网站的优势有哪些网络营销主要做什么

一个网站的优势有哪些,网络营销主要做什么,茄子河区网站建设自查报告,为什么做网站要服务器 和域名给定两个大小分别为 m 和 n 的正序(从小到大)数组 nums1 和 nums2。请你找出并返回这两个正序数组的 中位数 。算法的时间复杂度应该为 O(log (mn)) 。示例 1:输入:nums1 [1,3], nums2 [2] 输出:2.00000 解释&#x…

给定两个大小分别为 m 和 n 的正序(从小到大)数组 nums1 和 nums2。请你找出并返回这两个正序数组的 中位数 。

算法的时间复杂度应该为 O(log (m+n)) 。

示例 1:

输入:nums1 = [1,3], nums2 = [2]
输出:2.00000
解释:合并数组 = [1,2,3] ,中位数 2

示例 2:

输入:nums1 = [1,2], nums2 = [3,4]
输出:2.50000
解释:合并数组 = [1,2,3,4] ,中位数 (2 + 3) / 2 = 2.5

O(m+n)复杂度的方法

class Solution {
public:double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {int l1 = 0, l2 = 0, mid1, mid2;int r1 = nums1.size() - 1, r2 = nums2.size() - 1;int total = nums1.size() + nums2.size();bool is_odd = total % 2;int mid = total / 2;double result = 0.0;// 如果 nums1 为空if (nums1.empty()) {if (nums2.empty()) return 0.0; // 两个都空if (is_odd) return nums2[mid];return (nums2[mid - 1] + nums2[mid]) / 2.0;}// 如果 nums2 为空if (nums2.empty()) {if (is_odd) return nums1[mid];return (nums1[mid - 1] + nums1[mid]) / 2.0;}// 合并两个数组(直接模拟合并直到中位数)int i = 0, j = 0, count = 0;int prev = 0, curr = 0;while (count <= mid) {prev = curr;if (i < nums1.size() && (j >= nums2.size() || nums1[i] <= nums2[j])) {curr = nums1[i++];} else {curr = nums2[j++];}count++;}if (is_odd) return curr;return (prev + curr) / 2.0;}
};

O(LogMin(M,N))的方法

class Solution {
public:int getKthElement(const vector<int>& nums1, const vector<int>& nums2, int k) {int index1 = 0, index2 = 0;int n1 = nums1.size(), n2 = nums2.size();while (true) {// 特殊情况:nums1已经用完了if (index1 == n1) return nums2[index2 + k - 1];if (index2 == n2) return nums1[index1 + k - 1];// 如果只要第1小的数,直接比较两边头部if (k == 1) return min(nums1[index1], nums2[index2]);// 正常处理int half = k / 2;// 计算每个数组跳多少步int newIndex1 = min(index1 + half, n1) - 1;int newIndex2 = min(index2 + half, n2) - 1;int pivot1 = nums1[newIndex1];int pivot2 = nums2[newIndex2];// 谁的 pivot 小,谁的前面都不可能是第k小,全部丢掉if (pivot1 <= pivot2) {k -= (newIndex1 - index1 + 1);index1 = newIndex1 + 1;} else {k -= (newIndex2 - index2 + 1);index2 = newIndex2 + 1;}}}double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {int total = nums1.size() + nums2.size();// 奇数情况,找第 (n/2 + 1) 小if (total % 2 == 1) {return getKthElement(nums1, nums2, total / 2 + 1);} // 偶数情况,取中间两个平均else {return (getKthElement(nums1, nums2, total / 2) +getKthElement(nums1, nums2, total / 2 + 1)) / 2.0;}}
};

http://www.dtcms.com/wzjs/276453.html

相关文章:

  • 望城经开区建设开发公司门户网站广告媒体资源平台
  • 做教学的视频网站有哪些橘子seo历史查询
  • 睢县做网站哪家好友情链接平台广告
  • 做网站赚钱的时代过去了吗长尾词优化外包
  • 东莞网站建设信科分公司aso优化推广
  • 建一个网站需要购买域名 虚拟主机青岛seo整站优化
  • bluehost 安装wordpress宁波seo网络推广多少钱
  • 建设手机网银可以自己提升额度吗网站优化公司排名
  • 网站备案工信部时间青岛seo青岛黑八网络最强
  • 合肥网站系统建设公司企业的互联网推广
  • 网络推广的方式都有哪些西安网站优化公司
  • 西安教育平台网站建设网络运营是什么意思
  • 免费企业网站建设介绍app营销策略都有哪些
  • 广告设计制作图片seo教学平台
  • 首页网站关键词优化教程互联网营销策略有哪些
  • 邢台哪儿做wap网站好免费合作推广
  • 肯尼亚网站域名今年疫情最新消息
  • 对于网站建设的体会优化师的工作内容
  • asp中用jqure做网站外贸营销型网站制作公司
  • 网页设计网站开发邯郸百度推广公司
  • 网站建设与运营怎么在网上做广告
  • 做视频网站用哪个软件好chrome网页版入口
  • 上海网站设计公司有哪些百度投诉电话客服24小时
  • 做翻译的网站semir森马
  • 租二级目录做网站石家庄seo培训
  • 企业网站设计注意事项网络服务主要包括
  • 天津做网站选津坤科技月嫂免费政府培训中心
  • 网站没建好可以备案吗谷歌浏览器中文手机版
  • 有什么兼职做设计的网站好广州网站优化
  • 信息发布网站怎么做bing搜索引擎