当前位置:网站首页>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 ""
};
边栏推荐
- JVM系列——概述,程序计数器day1-1
- MySQL data processing value addition, deletion and modification
- PhpMyAdmin stage file contains analysis traceability
- Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
- Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
- Programmable logic device software testing
- Dlopen() implements dynamic loading of third-party libraries
- 28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
- Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
- Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
猜你喜欢

Implementation of Muduo asynchronous logging

Qt学习21 Qt 中的标准对话框(下)

Qt学习24 布局管理器(三)

【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明

SQL Injection (GET/Search)

28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;

Failure of vector insertion element iterator in STL

Using registered classes to realize specific type matching function template

Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm

Scroll detection of the navigation bar enables the navigation bar to slide and fix with no content
随机推荐
Example analysis of QT learning 18 login dialog box
Use vscode to view hex or UTF-8 codes
Qt学习19 Qt 中的标准对话框(上)
Spring cup eight school league
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
Dlopen() implements dynamic loading of third-party libraries
JS general form submission 1-onsubmit
QT learning 23 layout manager (II)
[技术发展-24]:现有物联网通信技术特点
GoLand 2021.1: rename the go project
28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
Screenshot of the operation steps of upload labs level 4-level 9
金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
GoLand 2021.1.1: configure the multi line display of the tab of the open file
Similarities and differences of sessionstorage, localstorage and cookies
[556. Next larger element III]
Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
Invalid Z-index problem
Rasp implementation of PHP
Go: send the get request and parse the return JSON (go1.16.4)