当前位置:网站首页>剑指offer专项突击版 ---第 5 天
剑指offer专项突击版 ---第 5 天
2022-07-31 05:09:00 【米兰的小红黑】

class Solution {
public boolean checkInclusion(String s1, String s2) {
int m = s1.length();
int n = s2.length();
if(m > n){
return false;
}
int[] arr1 = new int[26];
int[] arr2 = new int[26];
for(int i = 0; i < m; i++){
++arr1[s1.charAt(i) - 'a'];
++arr2[s2.charAt(i) - 'a'];
}
if(Arrays.equals(arr1,arr2)){
return true;
}
for(int j = m; j < n; j++){
++arr2[s2.charAt(j) - 'a'];
--arr2[s2.charAt(j - m) - 'a'];
if(Arrays.equals(arr1,arr2)){
return true;
}
}
return false;
}
}

class Solution {
public List<Integer> findAnagrams(String s, String p) {
List<Integer> list = new ArrayList<>();
int m = s.length();
int n = p.length();
if(n > m){
return list;
}
int[] arr1 = new int[26];
int[] arr2 = new int[26];
for(int i = 0; i < n; i++){
++arr1[s.charAt(i) - 'a'];
++arr2[p.charAt(i) - 'a'];
}
if(Arrays.equals(arr1,arr2)){
list.add(0);
}
for(int j = n; j < m; j++){
++arr1[s.charAt(j) - 'a'];
--arr1[s.charAt(j - n) - 'a'];
if(Arrays.equals(arr1,arr2)){
list.add(j - n + 1);
}
}
return list;
}
}

class Solution {
public int lengthOfLongestSubstring(String s) {
HashMap<Character, Integer> calc = new HashMap<>();
int left = 0;
int ret = 0;
for(int i = 0; i < s.length(); i++){
if(calc.containsKey(s.charAt(i))){
left = Math.max(left, calc.get(s.charAt(i)) + 1);
}
calc.put(s.charAt(i),i);
ret = Math.max(ret,i -left + 1);
}
return ret;
}
}
边栏推荐
- torch.normal函数用法
- matlab abel变换图片处理
- MySQL事务(transaction) (有这篇就足够了..)
- numpy和pytorch中的元素拼接操作:stack,concatenat,cat
- sql statement - how to query data in another table based on the data in one table
- mysql5.7.35安装配置教程【超级详细安装教程】
- Mysql application cannot find my.ini file after installation
- DVWA shooting range environment construction
- MySQL忘记密码怎么办
- 关于LocalDateTime的全局返回时间带“T“的时间格式处理
猜你喜欢

CentOS7 install MySQL graphic detailed tutorial

Interviewer, don't ask me to shake hands three times and wave four times again

工作流编排引擎-Temporal

有了MVC,为什么还要DDD?

MySQL-Explain详解

SQL injection of DVWA

MYSQL一站式学习,看完即学完

Typec手机有线网卡网线转网口转接口快充方案
![【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试](/img/7a/c70077c7a95137aaeb49c344c82696.png)
【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试

mysql stored procedure
随机推荐
信息系统项目管理师核心考点(五十五)配置管理员(CMO)的工作
Redis进阶 - 缓存问题:一致性、穿击、穿透、雪崩、污染等.
Blockbuster | foundation for platinum, gold, silver gave nameboards donors
有了MVC,为什么还要DDD?
mysql stored procedure
账号或密码多次输入错误,进行账号封禁
Flink sink ES 写入 ES(带密码)
MySQL_关于JSON数据的查询
mysql5.7.35安装配置教程【超级详细安装教程】
Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
Kubernetes加入集群的TOKEN值过期
MySQL window function
矩池云快速安装torch-sparse、torch-geometric等包
工作流编排引擎-Temporal
Three oj questions on leetcode
【mysql 提高查询效率】Mysql 数据库查询好慢问题解决
Unity mobile game performance optimization series: performance tuning for the CPU side
110道 MySQL面试题及答案 (持续更新)