码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 代码随想录算法训练营第三十七天| 860.柠檬水找零,406.根据身高重建队列 ,738.单调递增的数字


    860. 柠檬水找零 - 力扣(LeetCode)

    1. class Solution {
    2. public boolean lemonadeChange(int[] bills) {
    3. int fiveCount = 0;
    4. int tenCount = 0;
    5. for(int i=0;i
    6. if(bills[i] == 5){
    7. fiveCount++;
    8. }else if(bills[i] == 10){
    9. fiveCount--;
    10. tenCount++;
    11. }else{
    12. if(tenCount>0){
    13. tenCount--;
    14. fiveCount--;
    15. }else{
    16. fiveCount-=3;
    17. }
    18. }
    19. if(fiveCount<0 || tenCount<0){
    20. return false;
    21. }
    22. }
    23. return true;
    24. }
    25. }

    406. 根据身高重建队列 - 力扣(LeetCode)

    1. class Solution {
    2. public int[][] reconstructQueue(int[][] people) {
    3. //按身高进行排序
    4. Arrays.sort(people, (o1, o2) -> {
    5. if(o1[0] != o2[0]){
    6. return o2[0] - o1[0];
    7. }else{
    8. return o1[1] - o2[1];
    9. }
    10. });
    11. ArrayList<int[]> result = new ArrayList<>();
    12. for(int i=0;i
    13. result.add(people[i][1],people[i]);
    14. }
    15. return result.toArray(new int[people.length][2]);
    16. }
    17. }

     738. 单调递增的数字 - 力扣(LeetCode)

    1. class Solution {
    2. public int monotoneIncreasingDigits(int n) {
    3. if(n<10){
    4. return n;
    5. }
    6. char[] chars = (n + "").toCharArray();
    7. for(int i=chars.length-1;i>=1;i--){
    8. if(chars[i]1]){
    9. for(int j=i;j
    10. chars[j] = '9';
    11. }
    12. chars[i-1] = (char)(chars[i-1] - 1);
    13. }
    14. }
    15. return Integer.valueOf(new String(chars));
    16. }
    17. }
  • 相关阅读:
    高性能音乐流媒体服务Diosic
    golang 求立方根
    canvas绘制扫描图
    Windows 无法访问wsl ubuntu 中 docker 的端口
    L2-052 吉利矩阵
    一种无需调查船上坞的调查设备安装测量方法和安装测量系统
    Letter shell移植到AT32WB415
    HarmonyOS 3.1 第三方包导入
    深度学习的发展历程与未来展望
    c语言malloc不初始化,为什么没有占用系统空闲内存
  • 原文地址:https://blog.csdn.net/qq_15802379/article/details/139710384
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号