Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c530212

Browse files
rootroot
root
authored and
root
committed
fix: update solution No.1576
1 parent f6f2049 commit c530212

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

‎solution/1500-1599/1576.Replace All ?'s to Avoid Consecutive Repeating Characters/README.md‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# [1576. 替换所有的问号](https://leetcode-cn.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters)
22

3-
[English Version](/solution/1500-1599/1576.Replace%20All%20?'s%20to%20Avoid%20Consecutive%20Repeating%20Characters/README_EN.md)
3+
[English Version](/solution/1500-1599/1576.Replace%20All%20%3F's%20to%20Avoid%20Consecutive%20Repeating%20Characters/README_EN.md)
44

55
## 题目描述
66

@@ -75,7 +75,26 @@
7575
<!-- 这里可写当前语言的特殊实现逻辑 -->
7676

7777
```java
78-
78+
class Solution {
79+
public String modifyString(String s) {
80+
char[] chars = s.toCharArray();
81+
82+
for (int i = 0; i < chars.length; i++) {
83+
if (chars[i] == '?') {
84+
// 前面的字符
85+
char ahead = i == 0 ? ' ' : chars[i - 1];
86+
// 最后的字符
87+
char behind = i == chars.length - 1 ? ' ' : chars[i + 1];
88+
char temp = 'a';
89+
while (temp == ahead || temp == behind ) {
90+
temp++;
91+
}
92+
chars[i] = temp;
93+
}
94+
}
95+
return new String(chars);
96+
}
97+
}
7998
```
8099

81100
### **...**

‎solution/1500-1599/1576.Replace All ?'s to Avoid Consecutive Repeating Characters/README_EN.md‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# [1576. Replace All ?'s to Avoid Consecutive Repeating Characters](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters)
22

3-
[中文文档](/solution/1500-1599/1576.Replace%20All%20?'s%20to%20Avoid%20Consecutive%20Repeating%20Characters/README.md)
3+
[中文文档](/solution/1500-1599/1576.Replace%20All%20%3F's%20to%20Avoid%20Consecutive%20Repeating%20Characters/README.md)
44

55
## Description
66

@@ -70,7 +70,26 @@
7070

7171

7272
```java
73-
73+
class Solution {
74+
public String modifyString(String s) {
75+
char[] chars = s.toCharArray();
76+
77+
for (int i = 0; i < chars.length; i++) {
78+
if (chars[i] == '?') {
79+
// 前面的字符
80+
char ahead = i == 0 ? ' ' : chars[i - 1];
81+
// 最后的字符
82+
char behind = i == chars.length - 1 ? ' ' : chars[i + 1];
83+
char temp = 'a';
84+
while (temp == ahead || temp == behind ) {
85+
temp++;
86+
}
87+
chars[i] = temp;
88+
}
89+
}
90+
return new String(chars);
91+
}
92+
}
7493
```
7594

7695
### **...**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /