当前位置:网站首页>js . Find the first palindrome string in the array
js . Find the first palindrome string in the array
2022-07-03 14:06:00 【Cupid510】
Here's an array of strings words , Find and return... In the array First palindrome string . If there is no string that meets the requirements , Return to one An empty string “” .
Palindrome string For the definition of : If a string is read in the same way as it is read in the opposite direction , Then the string is a Palindrome string .
Example 1:
Input :words = [“abc”,“car”,“ada”,“racecar”,“cool”]
Output :“ada”
explain : The first palindrome string is “ada” .
Be careful ,“racecar” It's also a palindrome string , But it's not the first .
Example 2:
Input :words = [“notapalindrome”,“racecar”]
Output :“racecar”
explain : The first and only palindrome string is “racecar” .
source : Power button (LeetCode)
/** * @param {string[]} words * @return {string} */
var firstPalindrome = function(words) {
for(let i =0;i<words.length;i++){
let str = words[i]
let len = str.length
// Intermediate index
let index = parseInt(len / 2)
// The left character
let str1 = str.substring(0,index)
// On the right side
let str2=str.substring(len-index,len)
if(str2.split("").reverse().join("")==str1){
return str
}
}
return ""
};
边栏推荐
- Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
- 项目协作的进度如何推进| 社区征文
- PhpMyAdmin stage file contains analysis traceability
- MySQL 数据处理值增删改
- [acnoi2022] guess numbers
- Back to top implementation
- Summary of common error reporting problems and positioning methods of thrift
- Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides
- QT learning 19 standard dialog box in QT (top)
- 解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
猜你喜欢

JVM family - overview, program counter day1-1

Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
![[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心](/img/06/b71b505c7072d540955fda6da1dc1b.jpg)
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心

Redis:字符串類型數據的操作命令

解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)

Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS

There is nothing new under the sun. Can the meta universe go higher?
[email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂"/>金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂

Summary of common error reporting problems and positioning methods of thrift

Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
随机推荐
Summary of common error reporting problems and positioning methods of thrift
JVM class loading
金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
1px problem of mobile terminal
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
Generate directories from web content
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
Back to top implementation
Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
Webpage connection database ~ simple implementation of addition, deletion, modification and query complete code
How to delete an attribute or method of an object
QT learning 19 standard dialog box in QT (top)
JVM垃圾回收机
Qt学习18 登录对话框实例分析
jvm-运行时数据区
Qt学习23 布局管理器(二)
Leetcode-1175. Prime Arrangements
信创产业现状、分析与预测
MySQL 数据增删改查综合案例