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

Java算法 leetcode简单刷题记录5

Java算法 leetcode简单刷题记录5

  1. 老人的数目: https://leetcode.cn/problems/number-of-senior-citizens/
    substring(a,b) 前闭后开

  2. 统计能整除数字的位数: https://leetcode.cn/problems/count-the-digits-that-divide-a-number/
    并不复杂,直接写就行

  3. 从数量最多的堆取走礼物: https://leetcode.cn/problems/take-gifts-from-the-richest-pile/
    一堆数里依次每次取出最大值,或者最小值,都可以用优先级队列PriorityQueue;
    注意:最后求和int可能越界,用long类型

class Solution {public long pickGifts(int[] gifts, int k) {// 保证每次队列弹出最大值PriorityQueue<Integer> queue = new PriorityQueue<Integer>((obj1, obj2) -> {return obj2 - obj1;});for (int gift : gifts) {queue.add(gift);}int i = 0;while (i < k && queue.size() > 0) {int q = queue.poll();queue.add((int) Math.sqrt(q));i++;}long sum = 0;while (queue.size() > 0) {sum += queue.poll();}return sum;}
}
http://www.lryc.cn/news/286096.html

相关文章:

  • 计算机网络自顶向下Wireshark labs1-Intro
  • CSS实现图片放大缩小的几种方法
  • 时间序列预测 — CNN-LSTM-Attention实现多变量负荷预测(Tensorflow):多变量滚动
  • angular-tree-component组件中实现特定节点自动展开
  • Linux系统下安装Vcpkg,并使用Vcpkg安装、编译OpenSceneGraph
  • 设计模式二(工厂模式)
  • Maven应用手册
  • 笨蛋学设计模式行为型模式-状态模式【20】
  • C++从零开始的打怪升级之路(day18)
  • 浅谈安科瑞直流电表在新加坡光伏系统中的应用
  • C++参悟:数值运算相关
  • 【Web前端开发基础】CSS的定位和装饰
  • [pytorch入门] 3. torchvision中的transforms
  • WINCC读写EXCEL-VBS
  • Python os模块
  • Elasticsearch:2023 年 Lucene 领域发生了什么?
  • Java算法 leetcode简单刷题记录4
  • opencv#27模板匹配
  • 【论文阅读笔记】Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation
  • IS-IS:01 ISIS基本配置
  • 基于极限学习机的曲线分类,基于极限学习机的光谱分类,基于极限学习机的分类预测
  • miniconda安装
  • PHP判断访客是否手机端(移动端浏览器)访问的方法总结
  • vscode无法自动补全
  • 深度学习记录--指数加权平均
  • 如何生成图源二维码?
  • PowerShell install 一键部署grafana
  • 笨蛋学设计模式行为型模式-解释器模式【23】
  • SAP ABAP SUBMIT常用用法
  • GitLab备份与恢复测试(基于Docker)