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;

    }

}
相关推荐
SPC的存折4 分钟前
MySQL 8组复制完全指南
linux·运维·服务器·数据库·mysql
语戚12 分钟前
力扣 968. 监控二叉树 —— 贪心 & 树形 DP 双解法递归 + 非递归全解(Java 实现)
java·算法·leetcode·贪心算法·动态规划·力扣·
skywalker_1114 分钟前
力扣hot100-7(接雨水),8(无重复字符的最长子串)
算法·leetcode·职场和发展
quxuexi33 分钟前
网络通信安全与可靠传输:从加密到认证,从状态码到可靠传输
java·安全·web
hrhcode1 小时前
【java工程师快速上手go】二.Go进阶特性
java·golang·go
bIo7lyA8v1 小时前
算法稳定性分析中的输入扰动建模的技术9
算法
CoderCodingNo1 小时前
【GESP】C++三级真题 luogu-B4499, [GESP202603 三级] 二进制回文串
数据结构·c++·算法
sinat_286945191 小时前
AI Coding 时代的 TDD:从理念到工程落地
人工智能·深度学习·算法·tdd
炽烈小老头2 小时前
【 每天学习一点算法 2026/04/12】x 的平方根
学习·算法
ASKED_20192 小时前
从排序到生成:腾讯广告算法大赛 2025 baseline解读
人工智能·算法