当前位置:网站首页>Convert a string to an integer and don't double it
Convert a string to an integer and don't double it
2022-07-24 22:49:00 【InfoQ】
️ Convert a string to an integer ️
Topic details
"+2147483647"
2147483647
"1a33"
0
Their thinking
-isPosisPosfalsetrue+0['0', '9']0Source code
import java.util.*;
public class Solution {
public int StrToInt(String str) {
char[] cs = str.toCharArray();
int n = cs.length;
int ans = 0;
boolean isPos = true;
for (int i = 0; i < n; i++) {
char c = cs[i];
if (c > '0' && c < '9') {
ans = ans * 10 + (c - '0');
} else if (i == 0 && c == '-') {
isPos = false;
continue;
} else if (i == 0 && c == '+') {
continue;
} else {
return 0;
}
}
// Not positive.
if (!isPos) {
ans = -ans;
}
return ans;
}
}
summary
️ No two ️
Topic details
3 2
4
Their thinking
h*w01001(i+2, j)(i, j+2)1

Source code
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int w = sc.nextInt();
int h = sc.nextInt();
// Mark , by 0 Means to place the cake , Not 0 Means no cake
int[][] f = new int[h][w];
int ans = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (f[i][j] == 0) {
ans++;
// The update distance is 2 The location of the for 1
if (i + 2 < h) {
f[i + 2][j] = 1;
}
if (j + 2 < w) {
f[i][j + 2] = 1;
}
}
}
}
System.out.println(ans);
}
}
summary
01边栏推荐
- On the open and closed principle
- 《JUC并发编程 - 高级篇》05 -共享模型之无锁 (CAS | 原子整数 | 原子引用 | 原子数组 | 字段更新器 | 原子累加器 | Unsafe类 )
- Let‘s Encrypt
- How static code analysis works
- 力扣 1184. 公交站间的距离
- 郑慧娟:基于统一大市场的数据资产应用场景与评估方法研究
- Alibaba cloud SSL certificate
- What is a video content recommendation engine?
- Cross entropy loss
- Shell调试Debug的三种方式
猜你喜欢

Outlook邮件创建的规则失效,可能的原因

Pointrender parsing

Archsummit: evolution of the underlying framework of cherished microservices

Helm -- a powerful package management tool for kubernetes applications
![洛谷 P2024 [NOI2001] 食物链](/img/7f/6ccbc19942f0d4a153025346496834.png)
洛谷 P2024 [NOI2001] 食物链

Application programming of communication heartbeat signal for communication abnormality judgment
WPF uses pathgeometry to draw the hour hand and minute hand

Okaleido tiger NFT即将登录Binance NFT平台,后市持续看好

Kubernetes scheduling concept and workflow

生成式对抗网络的效果评估
随机推荐
HLS编程入门
Notes of Teacher Li Hongyi's 2020 in-depth learning series lecture 1
About the word 'don't remember'
Get the solution to the slow running speed of Mengxin Xiaobai computer! ٩ ( ‘ ω‘ )و get! ٩ ( ‘ ω‘ )و
Use kettle to read the data in Excel file and store it in MySQL
Process / thread synchronization mechanism
The tragic experience of installing scikitlearn on win764
力扣 1184. 公交站间的距离
先工程实践,还是先工程思想?—— 一位本科生从学oi到学开发的感悟
Backgroundworker enables time-consuming operations without affecting interface response
Which is the best interface documentation tool at home and abroad?
Burp's thinking from tracing to counteracting
Pointrender parsing
Connector in C
Network Security Learning (IV) user and group management, NTFS
谢振东:公共交通行业数字化转型升级的探索与实践
About constant modifier const
买收益百分之6的理财产品,需要开户吗?
"Fundamentals of program design" Chapter 10 function and program structure 7-2 Hanoi Tower problem (20 points)
物联网平台返回数据解析时遇到org.json.JSONException: No value for Value怎么办