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;

    }

}
相关推荐
蒟蒻小袁4 分钟前
力扣面试150题--二叉树的层平均值
算法·leetcode·面试
寻星探路6 分钟前
JAVA与C语言之间的差异(一)
java·开发语言
geneculture14 分钟前
技术-工程-管用养修保-智能硬件-智能软件五维黄金序位模型
大数据·人工智能·算法·数学建模·智能硬件·工程技术·融智学的重要应用
tqs_1234516 分钟前
IntelliJ IDEA 中进行背景设置
java·ide·intellij-idea
1001101_QIA17 分钟前
【QT】理解QT机制之“元对象系统”
开发语言·c++·qt·算法
a东方青25 分钟前
[蓝桥杯C++ 2024 国 B ] 立定跳远(二分)
c++·算法·蓝桥杯·c++20
爱上语文34 分钟前
MyBatisPlus(1):快速入门
java·开发语言·数据库·后端·mybatis
Studying 开龙wu40 分钟前
机器学习无监督学习sklearn实战一:K-Means 算法聚类对葡萄酒数据集进行聚类分析和可视化( 主成分分析PCA特征降维)
算法·机器学习·sklearn
异常君1 小时前
Java 与 Go 语言协作开发实战指南
java·go
似水এ᭄往昔1 小时前
【数据结构】--二叉树--堆(上)
数据结构·算法