国产美女主播视频一区_国产精品蜜臀在线观看_亚洲成人动漫一区_亚洲视屏在线播放

首頁 > 公益

Leetcode 2744. Find Maximum Number of String Pairs

來源:嗶哩嗶哩 時間:2023-06-25 13:45:38

You are given a?0-indexed?array?wordsconsisting of?distinct?strings.

The string?words[i]can be paired with the string?words[j]if:


(資料圖片僅供參考)

The string?words[i]is equal to the reversed string of?words[j].

0 <= i < j < words.length.

Return?the?maximum?number of pairs that can be formed from the array?words.

Note that?each string can belong in?at most one?pair.

Example 1:

Input: words = ["cd","ac","dc","ca","zz"]Output: 2Explanation: In this example, we can form 2 pair of strings in the following way:- We pair the 0th string with the 2nd string, as the reversed string of word[0] is "dc" and is equal to words[2].- We pair the 1st string with the 3rd string, as the reversed string of word[1] is "ca" and is equal to words[3].It can be proven that 2 is the maximum number of pairs that can be formed.

Example 2:

Input: words = ["ab","ba","cc"]Output: 1Explanation: In this example, we can form 1 pair of strings in the following way:- We pair the 0th string with the 1st string, as the reversed string of words[1] is "ab" and is equal to words[0].It can be proven that 1 is the maximum number of pairs that can be formed.

Example 3:

Input: words = ["aa","ab"]Output: 0Explanation: In this example, we are unable to form any pair of strings.

Constraints:

1 <= words.length <= 50

words[i].length == 2

wordsconsists of distinct strings.

words[i]contains only lowercase English letters.

找是否是反序的字符串對,用stringbuilder即可處理,

下面是代碼:

import java.util.Arrays;

public class Code2744 {

public static void main(String[] args) {

}

public static int maximumNumberofStringPairs(String[]words){

boolean[]bn=new boolean[words.length];

int cnt=0;

Arrays.fill(bn, false);

for (int i = 0; i < words.length-1; i++) {

for (int j = i+1; j < words.length; j++) {

if(check(words[i], words[j])&&bn[i]==false&&bn[j]==false){

bn[i]=true;

bn[j]=true;

cnt++;

}

}

}

return cnt;

}

public static boolean check(String a, String b){

StringBuilder sb=new StringBuilder(a);

if(sb.reverse().toString().equals(b)){

return true;

}else{

return false;

}

}

}

Runtime:?8 ms, faster than?33.33%?of?Java?online submissions for?Find Maximum Number of String Pairs.

Memory Usage:?43.9 MB, less than?33.33%?of?Java?online submissions for?Find Maximum Number of String Pairs.

相關稿件

Leetcode 2744. Find Maximum Number of String Pairs

全球熱推薦:IPO視頻 | 長風藥業IPO 負債率低于同行均值

5年期LPR為何只降10個基點 焦點信息

天天資訊:文保“活”起來 城市“火”起來

生死關頭,農民工師徒李羿、張勇明縱身跳入江中......

熱文:鵝湖書院景區:文明旅游 一路好風光

環球滾動:俄媒:普里戈任與瓦格納集團武裝人員已全部從俄南部軍區司令部撤離

白鶴灘-浙江特高壓工程輸電能力達800萬千瓦 環球速遞

三峽船閘通航20年累計貨運量19.1億噸

端午期間,港股風電板塊持續走低!

高容量鋰離子電池新型正極材料技術獲突破 天天觀速訊

全球報道:記者直擊丨莫斯科紅場附近街區夜間行人較往常明顯減少

氣象專家:厄爾尼諾將給我國帶來哪些影響?

制作鏡像系統u盤安裝系統-(制作鏡像系統u盤安裝系統教程)-每日訊息

綜合消息:普京向多國通報俄國內局勢 俄國防部呼吁瓦格納組織成員勿參加叛亂|視訊

焦點滾動:北方高溫稍稍減弱 9省市仍有35℃以上高溫

英特爾N100處理器性能曝光 跑分達i5-7400水平

大眾汽車重組各品牌并設置獨立績效 2030年銷售回報率提升至9%-11%-天天日報

深藍S7將于6月25日上市,預售價16.99萬起,軸距超Model Y 環球快消息

我國儲糧新技術處于國際領先水平 “智慧糧庫”讓小麥“凍齡” 環球觀察

預計年內上市 奇瑞TJ-1官方定名探索06

不只是蘋果 iPhone,英國稱安卓手機也存在 SOS 誤報問題

華為P60,近期好價,喜歡攝影的用戶切勿錯過 前沿熱點

長今之夢第二季第三十五集金剛山的老虎_長今之夢第二季

環球速看:罄竹難書系列作者_罄竹難書系列

智能大棚

國際排聯通過2028年洛杉磯奧運會參賽席位分配方式

要聞速遞:河南高考分數線公布:本科一批文科547分、理科514分

普里戈任稱接受瓦格納停止在俄領土上行動的提議 天天熱議

WTA伯明翰賽止步女單4強 朱琳草地賽季再創佳績|動態


主站蜘蛛池模板: 日韩欧美不卡在线| 欧美亚洲伦理www| 欧美国产综合视频| 99国产精品白浆在线观看免费| 国产精品一 二 三| 午夜精品一区二区三区av| 国产在线视频91| 国产精品视频二| 国产精品91久久| 欧美精品www| 欧美在线一区二区三区四| 日日夜夜精品网站| 国产日韩一区二区在线观看| 亚洲在线视频福利| 日本不卡一区二区三区视频| 国产在线拍揄自揄视频不卡99| 婷婷亚洲婷婷综合色香五月| 国产日产欧美视频| 一本二本三本亚洲码| 亚洲熟妇无码一区二区三区 | 草莓视频一区| 精品91免费| 欧美日韩一道本| 国产在线精品自拍| 国产99在线免费| 高清视频一区二区三区| 国产精品夫妻激情| 国产成人综合一区二区三区| 亚洲欧美日韩不卡| 中文字幕精品在线播放| 久久99热精品这里久久精品| 91精品综合久久| 中文字幕在线亚洲精品| 视频一区免费观看| 久久精品视频中文字幕| 97久久精品视频| 精品国偷自产在线视频99| 久久精品美女| 丝袜一区二区三区| 丝袜美腿精品国产二区| 国产日产亚洲精品|