当前位置:网站首页>Day10 daily 3 questions (3): String Matching in array
Day10 daily 3 questions (3): String Matching in array
2022-06-26 16:36:00 【Programmed ape without hair loss 2】
subject :
Here's an array of strings words , Each string in the array can be regarded as a word . Please press arbitrarily Sequential return words All words that are substrings of other words in .
If you can delete words[j] Leftmost and / Or the rightmost characters get word[i] , So the string words[i] Namely words[j] A substring of .
Example 1:
Input :words = [“mass”,“as”,“hero”,“superhero”]
Output :[“as”,“hero”]
explain :“as” yes “mass” Substring of ,“hero” yes “superhero” Substring of .
[“hero”,“as”] It's also a valid answer .
Example 2:
Input :words = [“leetcode”,“et”,“code”]
Output :[“et”,“code”]
explain :“et” and “code” All are “leetcode” Substring of .
Example 3:
Input :words = [“blue”,“green”,“bu”]
Output :[]
Tips :
1 <= words.length <= 100
1 <= words[i].length <= 30
words[i] Contains only lowercase English letters .
Subject data Guarantee Every words[i] They are unique .
adopt
Ideas :
Double traversal , Minimize the number of inner layer traversal .
java Code :
class Solution {
public List<String> stringMatching(String[] words) {
List<String> res = new ArrayList<>();
for (int i = 0; i < words.length-1; i++) {
for (int j = i+1; j < words.length; j++) {
if (!res.contains(words[j]) && words[i].contains(words[j])) {
res.add(words[j]);
} else if (!res.contains(words[i]) && words[j].contains(words[i])) {
res.add(words[i]);
}
}
}
return res;
}
}
边栏推荐
- Arduino UNO + DS1302简单获取时间并串口打印
- 基于Kubebuilder开发Operator(入门使用)
- JS教程之 使用 Electron.JS 构建原生桌面应用程序乒乓游戏
- 【力扣刷题】11.盛最多水的容器//42.接雨水
- 网页课程设计大作业——华山旅游网
- stm32h7b0替代h750程序导致单片机挂掉无法烧录程序问题
- JS tutorial - printing stickers / labels using the electronjs desktop application
- MS | Xie Liwei group found that mixed probiotics and their metabolites could alleviate colitis
- This year, the AI score of college entrance examination English is 134. The research of Fudan Wuda alumni is interesting
- Mono 的一些实例方法
猜你喜欢

Lifeifei's team applied vit to the robot, increased the maximum speed of planning reasoning by 512 times, and also cued hekaiming's Mae

100+ data science interview questions and answers Summary - basic knowledge and data analysis

若依如何实现接口限流?

Pybullet robot simulation environment construction 5 Robot pose visualization

Science | giant bacteria found in mangroves challenge the traditional concept of nuclear free membrane

IAR engineering adapts gd32 chip

当一个程序员一天被打扰 10 次,后果很惊人!

JUnit unit test

C语言所有知识点小结

知道这几个命令让你掌握Shell自带工具
随机推荐
Scala Basics (II): variables and data types
Science | 红树林中发现的巨型细菌挑战传统无核膜观念
Cookie和Session详解
若依如何实现接口限流?
100+数据科学面试问题和答案总结 - 基础知识和数据分析
Kept to implement redis autofailover (redisha) 1
Solidus labs welcomes zhaojiali, former head of financial innovation in Hong Kong, as a strategic adviser
Binary array command of redis
R language generalized linear model function GLM, GLM function to build logistic regression model, analyze whether the model is over discrete, and use the ratio of residual deviation and residual degr
数据分析----numpy快速入门
Niuke Xiaobai monthly race 50
Keepalived 实现 Redis AutoFailover (RedisHA)1
r329(MAIX-II-A(M2A)资料汇总
MS | Xie Liwei group found that mixed probiotics and their metabolites could alleviate colitis
【从删库到跑路】MySQL基础 完结篇(入个门先跑路了。。)
JUnit unit test
The details of the first pig heart transplantation were fully disclosed: human herpes virus was found in the patient, the weight of the heart doubled after death, and myocardial cell fibrosis
Dialogue with the senior management of Chang'an Mazda, new products will be released in Q4, and space and intelligence will lead the Japanese system
若依微服务特殊字符串被过滤的解决办法
SAP OData development tutorial - from getting started to improving (including segw, rap and CDP)