当前位置:网站首页>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 …
边栏推荐
- [Qualcomm][Network] qti服务分析
- WARNING: [pool www] server reached pm. max_ children setting (5), consider raising it
- Cause: could't make a guess for solution
- Use of selectors
- PLC概述
- Review of database -- 1. Overview
- 如何写一篇百万阅读量的文章
- Tower of Hanoi II | tower of Hanoi 4 columns
- Data communication foundation - layer 2 switching principle
- Basic usage of protobuf
猜你喜欢

Learning about opencv (4)

【Halcon视觉】仿射变换

【Halcon视觉】图像滤波

数通基础-TCPIP参考模型

About automatic operation on Web pages

Server memory failure prediction can actually do this!

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

Uniapp "no mobile phone or simulator detected, please try again later" and uniapp custom components and communication

protobuf的基本用法

如何写一篇百万阅读量的文章
随机推荐
Sublime install plug-ins
The problem of four columns of Hanoi Tower
Usage of the formatter attribute of El table
【Halcon视觉】图像滤波
How to write a million reading article
Wechat applet learning notes 2
C language course design Tetris (Part 2)
Principle analysis and source code interpretation of service discovery
SQL Server 2008 R2 installation problems
Learning about opencv (1)
Vs Code configures go locale and successfully installs go related plug-ins in vscode problem: Tools failed to install
What will the new Fuzhou Xiamen railway bring to Fujian coastal areas?
The charm of SQL optimization! From 30248s to 0.001s
Replay the snake game with C language (II) end
Learning about opencv (4)
Meeting OA project (III) -- my meeting (meeting seating and submission for approval)
Keeping alive to realize MySQL automatic failover
数通基础-二层交换原理
点赞,《新程序员》电子书限时免费领啦!
PHP executes shell script