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

学做网站有多难免费建网站

学做网站有多难,免费建网站,wordpress技术博客主题,推广app怎么做文章目录 一【题目类别】二【题目难度】三【题目编号】四【题目描述】五【题目示例】六【题目提示】七【解题思路】八【时间频度】九【代码实现】十【提交结果】 一【题目类别】 哈希表 二【题目难度】 困难 三【题目编号】 41.缺失的第一个正数 四【题目描述】 给你一个…

文章目录

  • 一【题目类别】
  • 二【题目难度】
  • 三【题目编号】
  • 四【题目描述】
  • 五【题目示例】
  • 六【题目提示】
  • 七【解题思路】
  • 八【时间频度】
  • 九【代码实现】
  • 十【提交结果】

一【题目类别】

  • 哈希表

二【题目难度】

  • 困难

三【题目编号】

  • 41.缺失的第一个正数

四【题目描述】

  • 给你一个未排序的整数数组 nums ,请你找出其中没有出现的最小的正整数。
  • 请你实现时间复杂度为 O(n) 并且只使用常数级别额外空间的解决方案。

五【题目示例】

  • 示例 1:

    • 输入:nums = [1,2,0]
    • 输出:3
  • 示例 2:

    • 输入:nums = [3,4,-1,1]
    • 输出:2
  • 示例 3:

    • 输入:nums = [7,8,9,11,12]
    • 输出:1

六【题目提示】

  • 1 < = n u m s . l e n g t h < = 5 ∗ 1 0 5 1 <= nums.length <= 5 * 10^5 1<=nums.length<=5105
  • − 2 31 < = n u m s [ i ] < = 2 31 − 1 -2^{31} <= nums[i] <= 2^{31} - 1 231<=nums[i]<=2311

七【解题思路】

  • 对数组中的元素进行“原地哈希”,第i个元素映射到i-1的位置
  • 这样,对于1-N中的元素,如果没有空缺,那么缺失的第一个正数一定是N+1;如果有空缺,那么缺失的第一个整数一定在1-N中
  • 然后我们遍历数组,对于映射不匹配的元素直接返回即可

八【时间频度】

  • 时间复杂度: O ( n ) O(n) O(n) n n n为传入的数组的长度
  • 空间复杂度: O ( 1 ) O(1) O(1)

九【代码实现】

  1. Java语言版
class Solution {public int firstMissingPositive(int[] nums) {int n = nums.length;for(int i = 0;i < n;i++){while(0 < nums[i] && nums[i] <= n && nums[nums[i] - 1] != nums[i]){swap(nums, nums[i] - 1, i);}}for(int i = 0;i < n;i++){if(nums[i] != i + 1){return i + 1;}}return n + 1;}public void swap(int[] nums, int index1, int index2){int temp = nums[index1];nums[index1] = nums[index2];nums[index2] = temp;}
}
  1. C语言版
void swap(int* nums, int index1, int index2)
{int temp = nums[index1];nums[index1] = nums[index2];nums[index2] = temp;
}int firstMissingPositive(int* nums, int numsSize)
{int n = numsSize;for(int i = 0;i < n;i++){while(0 < nums[i] && nums[i] <= n && nums[nums[i] - 1] != nums[i]){swap(nums, nums[i] - 1, i);}}for(int i = 0;i < n;i++){if(i + 1 != nums[i]){return i + 1;}}return n + 1;
}
  1. Python语言版
class Solution:def firstMissingPositive(self, nums: List[int]) -> int:n = len(nums)for i in range(0, n):while 1 <= nums[i] and nums[i] <= n and nums[nums[i] - 1] != nums[i]:self.swap(nums, nums[i] - 1, i)for i in range(0, n):if nums[i] != i + 1:return i + 1return n + 1def swap(self, nums, index1, index2):temp = nums[index1]nums[index1] = nums[index2]nums[index2] = temp
  1. C++语言版
class Solution {
public:int firstMissingPositive(vector<int>& nums) {int n = nums.size();for(int i = 0;i < n;i++){while(0 < nums[i] && nums[i] <= n && nums[nums[i] - 1] != nums[i]){swap(nums, nums[i] - 1, i);}}for(int i = 0;i < n;i++){if(nums[i] != i + 1){return i + 1;}}return n + 1;}void swap(vector<int>& nums, int index1, int index2){int temp = nums[index1];nums[index1] = nums[index2];nums[index2] = temp;}
};

十【提交结果】

  1. Java语言版
    在这里插入图片描述

  2. C语言版
    在这里插入图片描述

  3. Python语言版
    在这里插入图片描述

  4. C++语言版
    在这里插入图片描述

http://www.hkea.cn/news/917702/

相关文章:

  • 网站运维可以做哪些域名查询网站入口
  • 网站开发的基本语言外贸平台自建站
  • 女生自己做网站营销方法有哪些
  • 怎么自己做网站吓别人金融网站推广圳seo公司
  • 彩票网站的客服有做吗海淀seo搜索优化多少钱
  • 河源哪有做网站网页模板设计
  • 手机网站可以做英文版本吗近三天时政热点
  • 怎么做网站游戏网络优化排名培训
  • ic外贸网站建设黑帽seo技巧
  • 实业有限公司网站怎么做百度一下了你就知道官网
  • 企业电子商务网站推广平台有哪些渠道
  • 本地用织梦做网站百度的网站网址
  • 基础展示营销型型网站新闻发稿平台有哪些
  • 做游戏赚钱的网站最新新闻热点事件2022
  • 商务网站建设哪家好推广代理公司
  • 自己做网站是否要买云主机西安百度提升优化
  • 成都注册公司哪个区好分析网站推广和优化的原因
  • 模板建站杭州seo泽成
  • 济南网站建设公司川芎网络怎么注册自己的网址
  • linux下安装wordpress关键词优化排名查询
  • wordpress手机网站怎么做中央电视台一套广告价目表
  • 百家号如何给网站做推广推广方案是什么
  • 西安三网合一网站建设产品线上推广方案
  • 2023年免费b站入口百度网站优化
  • 响应式网站建设有利于seo网站发布与推广方案
  • 网页制作教程课件seo推广排名重要吗
  • 小规模纳税人企业所得税怎么征收广州seo招聘
  • 济南企业自助建站网络营销策划公司
  • iis 新建网站 要登录温州seo推广外包
  • 个人想做企业网站备案惠州seo代理商