day06

第一题

https://leetcode.cn/problems/actors-and-directors-who-cooperated-at-least-three-times/submissions/633926727/

代码

# Write your MySQL query statement below

select actor_id, director_id from ActorDirector group by actor_id, director_id having count(timestamp) >= 3

第二题

https://leetcode.cn/problems/total-characters-in-string-after-transformations-i/

代码

class Solution {

    private static final int MOD = 1000000007;

    public int lengthAfterTransformations(String s, int t) {

        int[] cnt = new int[26];

        for (char ch : s.toCharArray()) {

            ++cnt[ch - 'a'];

        }

        for (int round = 0; round < t; ++round) {

            int[] nxt = new int[26];

            nxt[0] = cnt[25];

            nxt[1] = (cnt[25] + cnt[0]) % MOD;

            for (int i = 2; i < 26; ++i) {

                nxt[i] = cnt[i - 1];

            }

            cnt = nxt;

        }

        int ans = 0;

        for (int i = 0; i < 26; ++i) {

            ans = (ans + cnt[i]) % MOD;

        }

        return ans;

    }

}

第三题

https://leetcode.cn/problems/find-three-consecutive-integers-that-sum-to-a-given-number/

代码

class Solution {

    public long[] sumOfThree(long num) {

        long mid = num / 3;

        long[] res = {};

        if(3 * mid == num){

            res = new long[]{ mid -1, mid, mid + 1};

        }

        return res;

    }

}

你可能感兴趣的:(leetcode每日三题,leetcode,算法,java)