day01

第一题

https://leetcode.cn/problems/game-play-analysis-i/submissions/632977238/

代码

复制代码
# Write your MySQL query statement below

SELECT t1.player_id, t1.event_date AS first_login

FROM Activity t1

JOIN (

    SELECT player_id, MIN(event_date) AS min_date

    FROM Activity

    GROUP BY player_id

) AS t2 ON t1.player_id = t2.player_id AND t1.event_date = t2.min_date;

第二题

https://leetcode.cn/problems/summary-ranges/?envType=problem-list-v2&envId=array

代码

复制代码
class Solution {

    public List<String> summaryRanges(int[] nums) {

        int cnt = 0;

        List<String> list = new ArrayList<>();

        StringBuilder builder = new StringBuilder();

        for(int i = 0; i < nums.length; i++){

            if(cnt == 0){

                builder.append(nums[i]);

                cnt++;

            } else {

                if(nums[i] - nums[i-1] != 1){

                    if(cnt != 1){

                        builder.append("->");

                        builder.append(nums[i-1]);

                    }

                    list.add(builder.toString());

                    cnt = 0;

                    builder.setLength(0);

                    i--;

                } else {

                    cnt++;

                }

            }

        }

        if(cnt > 0){

            if(cnt > 1){

                builder.append("->");

                builder.append(nums[nums.length-1]);

            }

            list.add(builder.toString());

        }

        return list;

    }

}

第三题

https://leetcode.cn/problems/sum-of-digits-of-string-after-convert/description/?envType=problem-list-v2&envId=**string

代码

复制代码
class Solution {

    public static final int[] table = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};

    public int getLucky(String s, int k) {

        StringBuilder builder = new StringBuilder();

        for(int i = 0; i < s.length(); i++){

            builder.append(table[s.charAt(i) - 'a']);

        }

        int sum = 0;

        while(k-- != 0){

            sum = 0;

            for(int i = 0; i < builder.length(); i++){

                sum += builder.charAt(i) - '0';

            }

            builder.setLength(0); // 逻辑清空

            builder.append(sum);

        }

        return sum;

    }

}
相关推荐
AGI前沿6 分钟前
AdamW的继任者?AdamHD让LLM训练提速15%,性能提升4.7%,显存再省30%
人工智能·算法·语言模型·aigc
Tan_Ying_Y8 分钟前
什么是垃圾回收算法 他的底层原理是什么?
算法
7***374515 分钟前
Java设计模式之工厂
java·开发语言·设计模式
Xの哲學21 分钟前
Linux 分区表深度技术剖析
linux·网络·算法·架构·边缘计算
写写闲篇儿28 分钟前
经典算法题剖析之传递信息(三)
算法
上不如老下不如小29 分钟前
2025年第七届全国高校计算机能力挑战赛初赛 Python组 编程题汇总
开发语言·python·算法
程序员小白条40 分钟前
你面试时吹过最大的牛是什么?
java·开发语言·数据库·阿里云·面试·职场和发展·毕设
折翅嘀皇虫1 小时前
fastdds.type_propagation 详解
java·服务器·前端
小年糕是糕手1 小时前
【C++】类和对象(二) -- 构造函数、析构函数
java·c语言·开发语言·数据结构·c++·算法·leetcode
豐儀麟阁贵1 小时前
8.2异常的抛出与捕捉
java·开发语言·python