当前位置:网站首页>每日一题,数组字符串的匹配问题
每日一题,数组字符串的匹配问题
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作为外层循环时就是编译错误的)
哪位大佬可以给我解答一下呢,十分感谢!
边栏推荐
- 1413. Stepwise Summation to Get Minimum Positive Numbers
- 34. 谈谈为什么要拆分数据库?有哪些方法?
- Regular backup of mysql database (retain backups for nearly 7 days)
- JS中初始化对象为null和空对象的区别
- order by injection and limit injection, and wide byte injection
- 预测股票涨跌看什么指标,如何预测明天股票走势
- 3-6月面经总结,200多页真题笔记和详解(含核心考点及6家大厂)
- 简单业务类
- 力扣(LeetCode)221. 最大正方形(2022.08.09)
- BUUCTF Notes (web)
猜你喜欢
![[Network Security] Practice AWVS Range to reproduce CSRF vulnerability](/img/7f/f08e429e3d8ede03a1c1754e256f99.png)
[Network Security] Practice AWVS Range to reproduce CSRF vulnerability

Grammar Basics (Judgment Statements)

navicat for mysql 连接时报错:1251-Client does not support authentication protocol requested by server

ESP32 485风速

COLMAP+OpenMVS realizes 3D reconstruction mesh model of objects

数据库公共字段自动填充

人工神经网络模型的特点,人工神经网络模型定义

WooCommerce 安装和 rest api 使用

delta method 介绍

自动化测试框架Pytest(二)——前后置处理
随机推荐
【愚公系列】2022年08月 Go教学课程 034-接口和多态
Text-to-Image最新论文、代码汇总
基于ABP的AppUser对象扩展
order by injection and limit injection, and wide byte injection
2022河南萌新联赛第(五)场:信息工程大学 F - 分割草坪
941 · Sliding Puzzles
Fiddler(八) - 抓取手机APP的流量-插件Fiddler Orchestra Beta安装&配置
navicat for mysql 连接时报错:1251-Client does not support authentication protocol requested by server
Elementary Structure
MySQL's InnoDB engine (6)
Discussion on Chinese Fuzzy Retrieval in Databases
关于数据中心的设计方案,数据中心网络规划设计
大佬,oracle单表增量同步时候源库服务器额外占用内存近2g,这不正常吧
Reproduce dns out-band data combined with sqlmap
时序动作定位 | ACGNet:弱监督时序动作定位的动作补充图网络(AAAI 2022)
阿里巴巴(中国)网络技术有限公司、测试开发笔试二面试题(附答案)
如何正确理解线程机制中常见的I/O模型,各自主要用来解决什么问题?
腾讯云宋翔:Kubernetes集群利用率提升实践
C language file operation
【Rust指南】使用Cargo工具高效创建Rust项目 | 理解Rust特别的输入输出语句