当前位置:网站首页>LeetCode-1576. Replace all question marks
LeetCode-1576. Replace all question marks
2022-06-12 06:22:00 【Border wanderer】
Here's a small alphabet and '?' String of characters s, Please put all the '?' Convert to a number of lowercase letters , So that the final string does not contain any Keep repeating The characters of .
Be careful : you You can't Modify non '?' character .
Topic test cases guarantee except '?' character outside , There are no consecutive repeated characters .
At the completion of all transformations ( There may be no need to convert ) After the return of the final string . If there are multiple solutions , Please return to any of them . Can prove that , Under given constraints , The answer is always there .
Example 1:
Input :s = "?zs"
Output :"azs"
explain : This example has 25 Kind of solution , from "azs" To "yzs" All of them meet the requirements of the title . Only "z" It's an invalid modification , Because strings "zzs" There are two consecutive repetitions in 'z' .
Example 2:
Input :s = "ubv?w"
Output :"ubvaw"
explain : This example has 24 Kind of solution , Only replace it with "v" and "w" Does not meet the requirements of the topic . because "ubvvw" and "ubvww" All contain characters that repeat continuously .
Example 3:
Input :s = "j?qg??b"
Output :"jaqgacb"
Example 4:
Input :s = "??yw?ipkj?"
Output :"acywaipkja"
Tips :
1 <= s.length <= 100
s Contains only lower case letters and '?' character
#include<iostream>
using namespace std;
class Solution {
public:
string modifyString(string s) {
if (s[0] == '?') {
s[0] = getonechar(s[1]);
}
for (int i = 1; i < s.length() - 1; i++) {
if (s[i] == '?') {
s[i] = getonechar(s[i - 1], s[i + 1]);
}
}
if (s[s.length() - 1] == '?') {
s[s.length() - 1] = getonechar(s[s.length() - 2]);
}
return s;
}
char getonechar(char a) {
for (char i = 'a'; i <= 'z'; i++) {
if (i != a) {
return i;
}
}
return a;
}
char getonechar(char a, char b) {
for (char i = 'a'; i <= 'z'; i++) {
if (i != a && i != b) {
return i;
}
}
return a;
}
};
边栏推荐
- Automatic modeling of Interchange
- Unity surface shader with template buffer
- 摄像头拍摄运动物体,产生运动模糊/拖影的原因分析
- English语法_副词_有无ly,意义不同
- Redis configuration (III) -- master-slave replication
- The vs 2019 community version Microsoft account cannot be logged in and activated offline
- Textcnn (MR dataset - emotion classification)
- Get the size of the picture
- Unreal Engine learning notes
- n次贝塞尔曲线
猜你喜欢

Houdini & UE4 programmed generation of mountains and multi vegetation scattering points

Bert Chinese classification model training + reasoning + deployment

Nodemon cannot load the file c:\users\administrator\appdata\roaming\npm\nodemon PS1, because script execution is prohibited in this system

哈工大信息内容安全实验

. Net core - pass Net core will Net to cross platform

Pytorch implementation of regression model

Automatic modeling of Interchange

姿态估计之2D人体姿态估计 - PifPaf:Composite Fields for Human Pose Estimation

UE4 4.27 modify the mobile forward pipeline to support cluster multi light source culling

cv2.fillPoly coco annotator segment坐标转化为mask图像
随机推荐
sqlite交叉编译动态库
Android studio mobile development creates a new database and obtains picture and text data from the database to display on the listview list
Leetcode January 12 daily question 334 Increasing ternary subsequence
Dlib face detection
Introduction to the method of diligently searching for the alliance procedure
线程有哪些状态?
JS pre parsing
Open the camera in unity3d and display the contents of the camera in the scene as texture2d
zip 和.items()区别
Redis队列
Piecewise Bezier curve
QT--实现TCP通信
leetcode 704. Binary search
Leetcode January 10 daily question 306 Additive number
Pytorch implementation of regression model
Computer composition and design work05 ——fifth verson
English语法_副词_有无ly,意义不同
Multithreading (V) -- Concurrent tools (II) -- j.u.c concurrent contracting (I) -- AQS and reentrantlock principles
Tips for using the potplayer video player
Summary of some problems in sensor bring up