当前位置:网站首页>*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';
}
}
}
};
边栏推荐
- Summary of pit websocket
- CA digital certificate
- GLIB-CRITICAL g_ file_ test:assertion ‘filename != null‘ failed
- About redis: there is still a risk of data loss after redis sets data persistence
- 落枕如何快速缓解
- Database connection pool & dbutils
- How to relieve the pillow quickly
- [video game training] non contact object size and shape measurement 2020 video game G
- NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library ‘*****‘
- scroll-view實現下拉刷新(避免onload進入頁面初始refresher-triggered為true觸發下拉問題)
猜你喜欢
![[video game training] non contact object size and shape measurement 2020 video game G](/img/b7/d70a702e52062e38176b589eb15415.jpg)
[video game training] non contact object size and shape measurement 2020 video game G

Interviewer: if the order is not paid within 30 minutes after it is generated, it will be automatically cancelled. How to realize it?

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

黑馬程序員-接口測試-四天學習接口測試-第四天-Postman讀取外部數據文件,讀取數據文件數據,iHRM項目實戰,員工管理模塊,添加員工,批量運行測試用例,生成測試報告,

Establishment of static route

Prometheus+node exporter+grafana monitoring server system resources

Database connection pool & dbutils

First knowledge of C language functions

多源文件方式去访问全局变量的方式(extern用法)
随机推荐
Leetcode set the intersection size to at least 2
C language writing specification
Sparksql design and introduction, 220722,
First knowledge of C language functions
What is promise? What are the benefits of promise
js的相关知识
Notes and Reflections on the red dust of the sky (V) strong culture and weak culture
Classic example of C language - print the input two digits in reverse order
How to relieve the pillow quickly
Blockbuster | certik: Web3.0 industry safety report release in the second quarter of 2022 (PDF download link attached)
How to realize 485 wireless communication between multiple sensors and Siemens PLC?
Tutorial on the principle and application of database system (048) -- MySQL query (x): self connection query
Tutorial on the principle and application of database system (049) -- MySQL query (XI): sub query
Bean Validation使用篇----05
freemarker
GLIB-CRITICAL g_ file_ test:assertion ‘filename != null‘ failed
Tutorial on principles and applications of database system (047) -- MySQL query (IX): connection query
Starfish OS: create a new paradigm of the meta universe with reality as the link
暑假第四周总结
Tutorial on principles and applications of database system (039) -- MySQL query (I): syntax analysis of select command