当前位置:网站首页>*offer--2
*offer--2
2022-07-24 00:55:00 【wzf6667】
Here's the catalog title
Title Description
Please implement a function , Replace each space in a string with “%20”. for example , When the string is We Are Happy. The replaced string is We%20Are%20Happy.
Direct use of replace Anencephalic operation
```java
public class Solution {
public String replaceSpace(StringBuffer str) {
for(int i = 0;i<str.length();i++){
char c = str.charAt(i);
if(c == ' '){
str.replace(i,i+1,"%20");
}
}
return str.toString();
}
}
// Online excerpts about stringbuffer Function of , and string There are still some different . In addition, regarding immutability, there is thread safety, which should be done by itself .
StringBuffer strbf=new StringBuffer("exception"); // Create a StringBuffer Class string
strbf.append(String s);// Appends the specified string to this character sequence .
strbf.reverse(); // Replace this character sequence with its inverted form .
strbf.delete(int start, int end); // Remove characters from substrings of this sequence .
strbf.insert(int offset, int i); // take int The string representation of the parameter is inserted into this sequence .
strbf.replace(int start, int end, String str); // Use given String The characters in replace the characters in the substring of this sequence .
no need replace Move characters according to the number of spaces , Then insert "%20"
Be careful “” and '‘ The difference between ! char Should use the ’' Otherwise, an error will be reported !
class Solution {
public:
void replaceSpace(char *str,int length) {
int count=0;
for(int i=0;i<length;i++){
if(str[i]==' ')
count++;
}
for(int i=length-1;i>=0;i--){
if(str[i]!=' '){
str[i+2*count]=str[i];
}
else{
count--;
str[i+2*count]='%';
str[i+2*count+1]='2';
str[i+2*count+2]='0';
}
}
}
};
边栏推荐
- JS drag and drop element
- Off screen rendering & FBO
- Selection method of geometric objects in Creo 9.0
- Classic example of C language - convert the input two digits into English
- 【数据挖掘工程师-笔试】2022年海尔 公司
- Blockbuster | certik: Web3.0 industry safety report release in the second quarter of 2022 (PDF download link attached)
- 入职3个月的测试员面临转正,领导:1年工作经验包装成5年,试用期淘汰
- Network system experiment: solve the problem of Ping failure
- [video game training] non contact object size and shape measurement 2020 video game G
- Is flush opening an account risky and safe?
猜你喜欢

Pbootcms database conversion tutorial (SQLite to MySQL detailed tutorial)

Educational Codeforces Round 132 (Rated for Div. 2) D. Rorororobot

This is a big problem

docker mysql

Graphic pipeline (I) post-processing stage alpha test template test depth test mix

入职3个月的测试员面临转正,领导:1年工作经验包装成5年,试用期淘汰

Database connection pool & dbutils
![[STM32] basic knowledge of serial communication](/img/0f/7cc59fea9b1edf721c9d06b419896a.png)
[STM32] basic knowledge of serial communication

Idea hot deployment (hot load)

PostgreSQL snapshot optimization globalvis new system analysis (greatly enhanced performance)
随机推荐
Classic example of C language - commodity inspection code
JS related knowledge
采坑websocket總結
Case error of MySQL branch statement
Problem note - unable to open include file: "direct.h": no such file or directory
Introduction to QT (2.1 the first procedure for the beginning of QT)
Analysis of the advantages of the LAAS scheme of elephant swap led to strong performance of ETOKEN
Tutorial on principles and applications of database system (043) -- MySQL query (V): Sorting Query Results
Tutorial on principles and applications of database system (042) -- MySQL query (4): using wildcards to construct query conditions
Fpga:ov7725 camera displays images in rgb565 format through vga/hdmi
[data mining engineer - written examination] Haier company in 2022
多源文件方式去访问全局变量的方式(extern用法)
AWS Part 4 one machine and one secret
Classic example of C language - find the minimum number of banknotes
C language writing specification
There are various signs that apple is expected to support AV1
ES6 combines multiple class methods
Communication module sorting (II) hc-05
網絡系統實驗:ping不通的問題解决
freemarker