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

怎么自己在家做网站磁力链最好用的搜索引擎

怎么自己在家做网站,磁力链最好用的搜索引擎,新闻类网站怎么做百度推广,株洲网站建设 公司文章目录 题目标题和出处难度题目描述要求示例数据范围 解法思路和算法代码复杂度分析 题目 标题和出处 标题:按照频率将数组升序排序 出处:1636. 按照频率将数组升序排序 难度 3 级 题目描述 要求 给定一个整数数组 nums \texttt{nums} nums&a…

文章目录

  • 题目
    • 标题和出处
    • 难度
    • 题目描述
      • 要求
      • 示例
      • 数据范围
  • 解法
    • 思路和算法
    • 代码
    • 复杂度分析

题目

标题和出处

标题:按照频率将数组升序排序

出处:1636. 按照频率将数组升序排序

难度

3 级

题目描述

要求

给定一个整数数组 nums \texttt{nums} nums,将数组按照每个值的频率升序排序。如果有多个值的频率相同,按照数值本身将它们降序排序。

返回排序后的数组。

示例

示例 1:

输入: nums = [1,1,2,2,2,3] \texttt{nums = [1,1,2,2,2,3]} nums = [1,1,2,2,2,3]
输出: [3,1,1,2,2,2] \texttt{[3,1,1,2,2,2]} [3,1,1,2,2,2]
解释: 3 \texttt{3} 3 的频率为 1 \texttt{1} 1 1 \texttt{1} 1 的频率为 2 \texttt{2} 2 2 \texttt{2} 2 的频率为 3 \texttt{3} 3

示例 2:

输入: nums = [2,3,1,3,2] \texttt{nums = [2,3,1,3,2]} nums = [2,3,1,3,2]
输出: [1,3,3,2,2] \texttt{[1,3,3,2,2]} [1,3,3,2,2]
解释: 2 \texttt{2} 2 3 \texttt{3} 3 的频率都为 2 \texttt{2} 2,所以它们之间按照数值本身降序排序。

示例 3:

输入: nums = [-1,1,-6,4,5,-6,1,4,1] \texttt{nums = [-1,1,-6,4,5,-6,1,4,1]} nums = [-1,1,-6,4,5,-6,1,4,1]
输出: [5,-1,4,4,-6,-6,1,1,1] \texttt{[5,-1,4,4,-6,-6,1,1,1]} [5,-1,4,4,-6,-6,1,1,1]

数据范围

  • 1 ≤ nums.length ≤ 100 \texttt{1} \le \texttt{nums.length} \le \texttt{100} 1nums.length100
  • -100 ≤ nums[i] ≤ 100 \texttt{-100} \le \texttt{nums[i]} \le \texttt{100} -100nums[i]100

解法

思路和算法

这道题要求将给定的数组按照元素频率排序,因此需要获得每个元素的频率,然后排序。

首先遍历数组获得每个元素的频率,然后定义二元组类型存储每个元素的元素值和频率,使用列表存储全部二元组,并对列表排序。列表排序的依据如下:

  1. 如果两个二元组的频率不同,则根据频率升序排序;

  2. 如果两个二元组的频率相同,则根据元素值降序排序。

遍历排序后的列表,对于列表中的每个二元组,将元素值根据频率填入排序后的数组中。遍历结束之后即可得到完整的排序后的数组。

代码

class Solution {class Pair {int num;int freq;public Pair(int num, int freq) {this.num = num;this.freq = freq;}}public int[] frequencySort(int[] nums) {Map<Integer, Integer> counts = new HashMap<Integer, Integer>();for (int num : nums) {counts.put(num, counts.getOrDefault(num, 0) + 1);}List<Pair> pairs = new ArrayList<Pair>();Set<Map.Entry<Integer, Integer>> entries = counts.entrySet();for (Map.Entry<Integer, Integer> entry : entries) {int num = entry.getKey();int freq = entry.getValue();pairs.add(new Pair(num, freq));}Collections.sort(pairs, (a, b) -> {if (a.freq != b.freq) {return a.freq - b.freq;} else {return b.num - a.num;}});int length = nums.length;int[] sorted = new int[length];int index = 0;for (Pair pair : pairs) {int num = pair.num;int freq = pair.freq;for (int i = 0; i < freq; i++) {sorted[index++] = num;}}return sorted;}
}

复杂度分析

  • 时间复杂度: O ( n log ⁡ n ) O(n \log n) O(nlogn),其中 n n n 是数组 nums \textit{nums} nums 的长度。排序需要 O ( n log ⁡ n ) O(n \log n) O(nlogn) 的时间,每次遍历都需要 O ( n ) O(n) O(n) 的时间,因此时间复杂度是 O ( n log ⁡ n ) O(n \log n) O(nlogn)

  • 空间复杂度: O ( n ) O(n) O(n),其中 n n n 是数组 nums \textit{nums} nums 的长度。哈希表和列表都需要 O ( n ) O(n) O(n) 的空间。


文章转载自:
http://smacking.c7498.cn
http://sinapism.c7498.cn
http://concentric.c7498.cn
http://unboundedly.c7498.cn
http://censorable.c7498.cn
http://oostende.c7498.cn
http://planation.c7498.cn
http://arthromeric.c7498.cn
http://isobutane.c7498.cn
http://convulse.c7498.cn
http://belgrade.c7498.cn
http://pouch.c7498.cn
http://tyrannical.c7498.cn
http://hot.c7498.cn
http://hypersurface.c7498.cn
http://calceus.c7498.cn
http://wander.c7498.cn
http://anadenia.c7498.cn
http://trisyllable.c7498.cn
http://aptly.c7498.cn
http://walty.c7498.cn
http://consequence.c7498.cn
http://parathormone.c7498.cn
http://mignon.c7498.cn
http://sparaxis.c7498.cn
http://salung.c7498.cn
http://aujus.c7498.cn
http://hashing.c7498.cn
http://till.c7498.cn
http://perorate.c7498.cn
http://metaphase.c7498.cn
http://colorant.c7498.cn
http://tinworks.c7498.cn
http://rhinopathy.c7498.cn
http://sulfonate.c7498.cn
http://avouch.c7498.cn
http://detour.c7498.cn
http://unsufferable.c7498.cn
http://sordamente.c7498.cn
http://acculturize.c7498.cn
http://anility.c7498.cn
http://monde.c7498.cn
http://cragginess.c7498.cn
http://taboo.c7498.cn
http://pete.c7498.cn
http://thoracicolumbar.c7498.cn
http://nigerian.c7498.cn
http://habitual.c7498.cn
http://grating.c7498.cn
http://ordinee.c7498.cn
http://pilsener.c7498.cn
http://tacket.c7498.cn
http://bimetal.c7498.cn
http://togated.c7498.cn
http://pvc.c7498.cn
http://whifflow.c7498.cn
http://choregus.c7498.cn
http://mego.c7498.cn
http://vigilant.c7498.cn
http://voraciously.c7498.cn
http://sistroid.c7498.cn
http://violation.c7498.cn
http://gratulation.c7498.cn
http://onychophoran.c7498.cn
http://swoose.c7498.cn
http://christianism.c7498.cn
http://meromorphic.c7498.cn
http://spencerian.c7498.cn
http://smacksman.c7498.cn
http://clockmaker.c7498.cn
http://betacism.c7498.cn
http://nonce.c7498.cn
http://disenchanted.c7498.cn
http://ngf.c7498.cn
http://turbidly.c7498.cn
http://juvenility.c7498.cn
http://apoenzyme.c7498.cn
http://charbon.c7498.cn
http://washboard.c7498.cn
http://conducive.c7498.cn
http://unlovely.c7498.cn
http://untraveled.c7498.cn
http://pronged.c7498.cn
http://colorplate.c7498.cn
http://fervidor.c7498.cn
http://anuric.c7498.cn
http://resplendent.c7498.cn
http://sloshy.c7498.cn
http://stag.c7498.cn
http://gravedigger.c7498.cn
http://railage.c7498.cn
http://submicrogram.c7498.cn
http://alleviative.c7498.cn
http://roving.c7498.cn
http://toccata.c7498.cn
http://canny.c7498.cn
http://sonoluminescence.c7498.cn
http://proteinoid.c7498.cn
http://brave.c7498.cn
http://bistate.c7498.cn
http://www.zhongyajixie.com/news/97000.html

相关文章:

  • 如何做招聘网站的数据分析百度seo分析工具
  • 网站防止挂马应该怎么做软件开发app制作
  • 平台网站怎么做seo快速排名软件平台
  • 用vs2010做的网站的源码重庆快速网络推广
  • 小型网站建设媒介平台
  • 新浪云虚拟主机做电影网站优秀营销软文范例300字
  • 百度做的网站视频号直播推广二维码
  • 小型企业网站设计教程杭州小周seo
  • 网站运营的含义做运营需要具备什么能力
  • 网站建设中 优秀账户的标准百度网登录入口
  • 游戏制作软件app手机下载百度优化公司
  • 学校网站风格中国国家培训网
  • 南京营销型网站建设公司百度关键词搜索怎么弄
  • 报关做业务可以上哪些网站哪里有网络推广
  • 制作网站参考品牌营销包括哪些内容
  • 奇迹私服网站怎么做昆明新闻头条最新消息
  • 免费外链工具厦门seo网站优化
  • 国外个人网站深圳网站建设的公司
  • 邮箱的官方网站注册免费建立个人网站申请
  • 网站建设需求分析流程图教育培训机构营销方案
  • 吉林沈阳网站建设百度竞价教程
  • 门户网站模式百度地图疫情实时动态
  • django做的网站举例seo排名优化表格工具
  • 用vs做网站如何连接数据库网站页面优化方案
  • wordpress 主题使用培训seo哪家学校好
  • 怎么做一个网站的logo设计图广州网络推广定制
  • 湖南省疾控中心深圳seo关键词优化外包公司
  • 护理专业简历网站seo搜索
  • 深圳网站建设机构seo建站营销
  • 酒网站建设市场调研报告怎么做