当前位置:网站首页>[jzof] 05 replace spaces
[jzof] 05 replace spaces
2022-07-24 21:05:00 【Sighed, angry】

import java.util.*;
public class Solution {
/** * The class name in the code 、 Method name 、 The parameter name has been specified , Do not modify , Return the value specified by the method directly * * * @param s string character string * @return string character string */
public String replaceSpace(String s) {
if (s.length() == 0){
return s;
}
int blankNum = 0;
// Calculate the number of spaces
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 32){
blankNum++;
}
}
// The length of the array after replacement
int newStrLen = s.length() + blankNum*2;
// Expand the source string
char[] chars = Arrays.copyOf(s.toCharArray(), newStrLen);
int oldEndIndex = s.length() -1;
int newEndIndex = newStrLen - 1;
for (;oldEndIndex>=0;oldEndIndex--,newEndIndex--){
if (oldEndIndex == newEndIndex){
return new String(chars);
}
if (s.charAt(oldEndIndex) == 32){
chars[newEndIndex] = '0';
chars[--newEndIndex] = '2';
chars[--newEndIndex] = '%';
}else {
chars[newEndIndex] = s.charAt(oldEndIndex);
}
}
return new String(chars);
}
}
边栏推荐
- [basic data mining technology] exploratory data analysis
- Open source demo | release of open source example of arcall applet
- Defects of matrix initialization
- Press Ctrl to pop up a dialog box. How to close this dialog box?
- Five digital transformation strategies of B2B Enterprises
- How to set the allure test report
- What should Ali pay attention to during the interview? Personal account of Alibaba interns who passed five rounds of interviews
- Career development suggestions shared by ten CIOs
- Mysql database query is so slow. Besides index, what else can it do?
- What does software testing need to learn?
猜你喜欢

Methods of using tyrosine modified peptide nucleic acid PNA | Tyr PNA | BZ Tyr PNA | 99Tcm survivinmrna antisense peptide nucleic acid
![[basic data mining technology] exploratory data analysis](/img/0c/1b73098a589a2af398dd3cd9d62cd7.png)
[basic data mining technology] exploratory data analysis

C synchronous asynchronous callback state machine async await demo

Native applets are introduced using vant webapp

Opencv learning Day2

Alibaba sentinel basic operation
![[advanced data mining technology] Introduction to advanced data mining technology](/img/93/cb5ee07bff50662ad2496ca2bb39da.png)
[advanced data mining technology] Introduction to advanced data mining technology

The difference between map and flatmap in stream

What should Ali pay attention to during the interview? Personal account of Alibaba interns who passed five rounds of interviews

ECCV 2022 open source | target segmentation for 10000 frames of video
随机推荐
[sciter]: window communication
[msp430g2553] graphical development notes (1) configuration environment
Baidu PaddlePaddle easydl helps improve the inspection efficiency of high-altitude photovoltaic power stations by 98%
High soft course summary
93. Recursive implementation of combinatorial enumeration
Merge sort
Selenium is detected as a crawler. How to shield and bypass it
Oracle creates table spaces and views table spaces and usage
C # image template matching and marking
Rce (no echo)
Markdown to PDF API data interface
How to set the allure test report
Go language error handling
Spark related FAQ summary
250 million, Banan District perception system data collection, background analysis, Xueliang engineering network and operation and maintenance service project: Chinatelecom won the bid
Let's make a nice monthly temperature map of China with ArcGIS
Node installation using NVM succeeded, but NPM installation failed (error while downloading, TLS handshake timeout)
How to prevent weight under Gao Bingfa?
ma.glasnost.orika. MappingException:No converter registered for conversion from Date to LocalDateTime
Generate self signed certificate: generate certificate and secret key