当前位置:网站首页>Competition question 2022-6-26
Competition question 2022-6-26
2022-07-06 01:40:00 【Yake1965】
6104. Statistical asterisk
class Solution:
def countAsterisks(self, s: str) -> int:
return "".join(s.split("|")[::2]).count("*")
flag, ans = 1, 0
for c in s:
if c == "*": ans += flag
elif c == "|": flag = 1 - flag
return ans
a = s.split('|')
return sum(a[i].count("*") for i in range(0, len(a), 2))
6107. The number of different die sequences
The first i The result of throwing dice for the first time is affected by (i - 1) Time and number (i - 2) Limit of secondary results . So we maintain f(i, a, b) It means the first one i The result of this dice throw is a, The first (i - 1) The result of this time is b Number of alternatives .
In order to transfer , Let's enumerate the third (i - 2) Results of c. According to the meaning ,a,b,c The following requirements need to be met :
The three numbers are not equal to each other ;
gcd(a, b) = gcd(b, c) = 1.
As long as these two conditions are met at the same time ,f(i - 1, b, c) Can be transferred to f(i, a, b).
The first 300 Weekly match
2325. Decrypt the message
class Solution {
public String decodeMessage(String key, String message) {
Map<Character, Character> map = new HashMap<>();
int i = 97;
for(char c : key.toCharArray()){
if(c == ' ') continue;
if(!map.containsKey(c)) map.put(c, (char)(i++));
}
map.put(' ', ' ');
StringBuilder sb = new StringBuilder();
for(char c : message.toCharArray()){
sb.append(map.get(c));
}
return sb.toString();
}
}
2326. Spiral matrix IV
class Solution {
public int[][] spiralMatrix(int m, int n, ListNode head) {
int[][] ans = new int[m][n];
for(int[] row : ans) Arrays.fill(row, -1);
int up = 0, down = m - 1, left = 0, right = n - 1;
while(head != null){
for(int j = left; head != null && j <= right; j++){
ans[up][j] = head.val;
head = head.next;
}
up++;
for(int i = up; head != null && i <= down; i++){
ans[i][right] = head.val;
head = head.next;
}
right--;
for(int j = right; head != null && j >= left; j--){
ans[down][j] = head.val;
head = head.next;
}
down--;
for(int i = down; head != null && i >= up; i--){
ans[i][left] = head.val;
head = head.next;
}
left++;
}
return ans;
}
}
2327. Number of people who know the secret
f[i] It means the first one i Tianxin knows the number of Secrets .
class Solution {
public int peopleAwareOfSecret(int n, int delay, int forget) {
int mod = 1000000007;
long s = 0;
long[] f = new long[n + 1];
f[1] = 1;
for(int i = 2; i <= n; i++){
if(i > delay) s += f[i-delay];
if(i > forget) s -= f[i-forget];
f[i] = s % mod;
}
long sum = 0;
for(int i = 0; i < forget; i++){
sum = (sum + f[n - i]) % mod;
}
return (int)sum;
}
}
2328. The number of incremental paths in the grid graph
边栏推荐
- Unity VR resource flash surface in scene
- Maya hollowed out modeling
- Redis守护进程无法停止解决方案
- 竞价推广流程
- ORA-00030
- National intangible cultural heritage inheritor HD Wang's shadow digital collection of "Four Beauties" made an amazing debut!
- c#网页打开winform exe
- MATLB|实时机会约束决策及其在电力系统中的应用
- Leetcode skimming questions_ Invert vowels in a string
- TrueType字体文件提取关键信息
猜你喜欢

NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】

3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video

插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制

NiO related knowledge (II)

Docker compose配置MySQL并实现远程连接

Redis-字符串类型

Maya hollowed out modeling
Folio.ink 免费、快速、易用的图片分享工具

【Flask】官方教程(Tutorial)-part2:蓝图-视图、模板、静态文件
Folio. Ink is a free, fast and easy-to-use image sharing tool
随机推荐
Leetcode skimming questions_ Verify palindrome string II
干货!通过软硬件协同设计加速稀疏神经网络
2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
500 lines of code to understand the principle of mecached cache client driver
【Flask】获取请求信息、重定向、错误处理
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
2 power view
Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
Yii console method call, Yii console scheduled task
[Jiudu OJ 09] two points to find student information
MATLB | real time opportunity constrained decision making and its application in power system
Crawler request module
NumPy 数组索引 切片
Ordinary people end up in Global trade, and a new round of structural opportunities emerge
MUX VLAN configuration
Flowable source code comments (36) process instance migration status job processor, BPMN history cleanup job processor, external worker task completion job processor
MySQL learning notes 2
竞价推广流程
3D视觉——4.手势识别(Gesture Recognition)入门——使用MediaPipe含单帧(Singel Frame)和实时视频(Real-Time Video)
Internship: unfamiliar annotations involved in the project code and their functions