2024/9/29 每日一题与周赛
This commit is contained in:
parent
a23a476d21
commit
e7fc73bb0b
|
@ -0,0 +1,35 @@
|
|||
package com.cool.one_question_per_day;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
*
|
||||
* @Author: Cool
|
||||
* @Date: 2024/09/29/10:31
|
||||
* DayNumber 1
|
||||
* Hard 1
|
||||
* Level 3
|
||||
* Score 1325
|
||||
* @Link https://leetcode.cn/problems/time-needed-to-buy-tickets/description/?envType=daily-question&envId=2024-09-29
|
||||
* @Description 2073. 买票需要的时间
|
||||
*/
|
||||
public class LeetCode20240929 {
|
||||
|
||||
public int timeRequiredToBuy(int[] tickets, int k) {
|
||||
int ticket=tickets[k];
|
||||
int res=0;
|
||||
for(int i=0;i<tickets.length;i++){
|
||||
if(i<=k){
|
||||
res += Math.min(tickets[i], ticket);
|
||||
}else{
|
||||
res += Math.min(tickets[i], ticket - 1);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@Test
|
||||
public void test(){
|
||||
timeRequiredToBuy(new int[]{2,3,2},2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.cool.week_match.week417;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
*
|
||||
* @Author: Cool
|
||||
* @Date: 2024/09/29/10:51
|
||||
* @Description:
|
||||
*/
|
||||
public class Q1 {
|
||||
|
||||
public char kthCharacter(int k) {
|
||||
if (k == 0) {
|
||||
return ' ';
|
||||
}
|
||||
Deque<Character> queue = new LinkedList<>();
|
||||
queue.offerLast('a');
|
||||
while (queue.size() < k) {
|
||||
char c = queue.pollFirst();
|
||||
char next;
|
||||
if (c == 'z') {
|
||||
next = 'a';
|
||||
} else {
|
||||
next = (char) (c + 1);
|
||||
}
|
||||
queue.offerLast(c);
|
||||
queue.offerLast(next);
|
||||
}
|
||||
while (queue.size() > k) {
|
||||
queue.pollLast();
|
||||
}
|
||||
return queue.peekLast();
|
||||
}
|
||||
@Test
|
||||
public void test(){
|
||||
kthCharacter(5);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue