当前位置:网站首页>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 ""
};
边栏推荐
- JS general form submission 1-onsubmit
- Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
- Uniapp tips - scrolling components
- Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
- [combinatorics] permutation and combination (two counting principles, examples of set permutation | examples of set permutation and circle permutation)
- Qt学习20 Qt 中的标准对话框(中)
- How to promote the progress of project collaboration | community essay solicitation
- Record 405 questions about bank callback post request
- Global event bus
- 【吉林大学】考研初试复试资料分享
猜你喜欢

【吉林大学】考研初试复试资料分享

全局事件总线

Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
![Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:](/img/2f/33504391a661ecb63d42d75acf3a37.png)
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:

Redis: commandes d'action pour les données de type chaîne
[email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂"/>金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂

GoLand 2021.1: rename the go project

MySQL 数据增删改查综合案例

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
[email protected] Nanoparticles) | nano metal organic framework carry"/>Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
随机推荐
Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride(
Qt学习17 对话框及其类型
Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
Uniapp tips - scrolling components
消息订阅与发布
Redis: redis data structure and key operation commands
Implementation of Muduo asynchronous logging
【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
如何使用lxml判断网站公告是否更新
Qt学习22 布局管理器(一)
Current situation, analysis and prediction of information and innovation industry
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
SQL Injection (AJAX/JSON/jQuery)
Vite project commissioning
Common mixins
page owner特性浅析
MySQL 数据处理值增删改
Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ