当前位置:网站首页>Li Kou daily question 917
Li Kou daily question 917
2022-07-26 10:18:00 【Fabulouskkk】
Yesterday was Hard Today is Easy 了 hhhh
Two pointers traverse from front to back , One goes back and forth , Two pointers pointing to letters at the same time is a direct exchange , Then together ++、–
Otherwise, each ++,–
public static String reverseOnlyLetters(String s) {
char[] chars = new char[s.length()];
for (int i = 0; i < chars.length; i++) {
chars[i] = s.charAt(i);
}
int leftIndex = 0;
int rightIndex = chars.length - 1;
while (leftIndex < rightIndex) {
if (Character.isLetter(chars[leftIndex]) && Character.isLetter(chars[rightIndex])) {
swap(chars, leftIndex, rightIndex);
leftIndex++;
rightIndex--;
} else if (!Character.isLetter(chars[rightIndex])) {
rightIndex--;
} else if (!Character.isLetter(chars[leftIndex])) {
leftIndex++;
}
}
return new String(chars);
}
private static void swap(char[] chars, int leftIndex, int rightIndex) {
char temp = chars[leftIndex];
chars[leftIndex] = chars[rightIndex];
chars[rightIndex] = temp;
}
char Type array to String When outputting new String Object of type , Otherwise, the output address …
边栏推荐
- 网易云UI模仿--&gt;侧边栏
- 【Halcon视觉】图像滤波
- 服务发现原理分析与源码解读
- INSTALL_FAILED_SHARED_USER_INCOMPATIBLE错误解决方式
- What will the new Fuzhou Xiamen railway bring to Fujian coastal areas?
- Wechat H5 payment on WAP, for non wechat browsers
- The charm of SQL optimization! From 30248s to 0.001s
- Phpexcel export Emoji symbol error
- Getting started with SQL - combined tables
- Study on the basis of opencv
猜你喜欢

About automatic operation on Web pages

Distributed network communication framework: how to publish local services into RPC services

新建福厦铁路全线贯通 这将给福建沿海带来什么?

Common errors when starting projects in uniapp ---appid

【Halcon视觉】形态学腐蚀

Keeping alive to realize MySQL automatic failover

Basics of data communication - basic knowledge of network

Data communication foundation - layer 2 switching principle

【Halcon视觉】图像滤波

Mysql5.7.25 master-slave replication (one-way)
随机推荐
Netease cloud UI imitation -- & gt; sidebar
Mysql5.7.25 master-slave replication (one-way)
Yarn 'TSC' is not an internal or external command, nor is it a runnable program or batch file. The problem that the command cannot be found after installing the global package
汉诺塔II|汉诺塔4柱
Set view dynamic picture
【Halcon视觉】图像滤波
30 minutes to thoroughly understand the synchronized lock upgrade process
数通基础-网络基础知识
Phpexcel export Emoji symbol error
Interview shock 68: why does TCP need three handshakes?
What will the new Fuzhou Xiamen railway bring to Fujian coastal areas?
Tableviewcell highly adaptive
Principle analysis and source code interpretation of service discovery
Beginner of flask framework-04-flask blueprint and code separation
Encapsulation of tabbarcontroller
Use of pclint in vs2013
Android greendao数据库的使用
Use of selectors
Nodejs service background execution (forever)
面试突击68:为什么 TCP 需要 3 次握手?