当前位置:网站首页>每日一题,数组字符串的匹配问题
每日一题,数组字符串的匹配问题
2022-08-10 06:59:00 【小魏爱炸毛】
今天,小魏为大家带来新的题

在做这个题的时候我们采用数组遍历的形式,用Java中的contains函数看words【j】当中是否存在words【i】,若存在,则在这个数组中增加这个结果,并且退出,如果没有,则返回这个数组
代码如下
class Solution {
public List<String> stringMatching(String[] words) {
List<String> tmp=new ArrayList<>();//创建数组
int n=words.length;//求数组长度
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i!=j&&words[j].contains(words[i])){
//子串不等于母串
tmp.add(words[i]);
break;
}
}
}
return tmp;
}
}这道题我想不通的一点是既然看的是words[j]中是否存在words[i],那么j的范围应该要大于i的范围,所以应该把j放在外层循环啊?(我在解答时将j作为外层循环时就是编译错误的)
哪位大佬可以给我解答一下呢,十分感谢!
边栏推荐
- Text-to-Image最新论文、代码汇总
- delta method 介绍
- 自组织是管理者和成员的双向奔赴
- COLMAP+OpenMVS realizes 3D reconstruction mesh model of objects
- Tencent Cloud Song Xiang: Kubernetes cluster utilization improvement practice
- 如何治理资源浪费?百度云原生成本优化最佳实践
- MVCC详解
- PLSQL学习第四天
- Discussion on Chinese Fuzzy Retrieval in Databases
- 基于STC8G2K64S4单片机通过OLED屏幕显示模拟量光敏模拟值
猜你喜欢
![Chapter 12 Other Database Tuning Strategies [2. Index and Tuning] [MySQL Advanced]](/img/6d/f7fffb327f3191ac4c5a3dc7808c89.png)
Chapter 12 Other Database Tuning Strategies [2. Index and Tuning] [MySQL Advanced]

神经网络的三种训练方法,神经网络训练全过程

自动化测试框架Pytest(二)——前后置处理

Confluence可以连接数据库但是在下一步就报错了

WooCommerce installation and rest api usage

1413. Stepwise Summation to Get Minimum Positive Numbers

High quality WordPress download station 5 play theme template

基于STC8G2K64S4单片机通过OLED屏幕显示模拟量光敏模拟值

初使jest 单元测试

Grammar Basics (Judgment Statements)
随机推荐
delta method 介绍
【Event Preview on August 9】Prometheus Summit
一文2600字手把手教你编写性能测试用例
【电商业务】外行为何难区别 商品属性与商品规格
WooCommerce installation and rest api usage
如何设计神经网络结构,神经网络设计与实现
[网络安全]实操AWVS靶场复现CSRF漏洞
英国国家卫生服务遭受攻击,系统出现大面积故障
排序二叉树代码
请问为什么sqlserver cdc,任务启动过了一天,会报这个错误,明明已经开启cdc了。
浅谈C语言实现冒泡排序
initramfs与initrd的区别
ES13 - ES2022 - The 123rd ECMA Congress approves the ECMAScript 2022 language specification
Tencent Cloud Song Xiang: Kubernetes cluster utilization improvement practice
2022河南萌新联赛第(五)场:信息工程大学 K - 矩阵生成
About MongoDb query Decimal128 to BigDecimal problem
预测股票涨跌看什么指标,如何预测明天股票走势
CuteOneP is a PHP-based OneDrive multi-network disk mount program with member synchronization and other functions
MVCC详解
Chapter 11 Database Design Specifications [2. Index and Tuning] [MySQL Advanced]