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

class Solution {
public String minWindow(String s, String t) {
int n = s.length(),m = t.length();
if(n<m) return "";
int[] cnt = new int[150];
int k = 0;
for(char c:t.toCharArray()){
if(++cnt[c]==1){
k++;
}
}
int l = 0,left = 0,right = 0;
for(int i = 0;i<s.length();i++){
char c = s.charAt(i);
if(--cnt[c]==0) k--;
if(k==0){
while(cnt[s.charAt(l)]<0){
++cnt[s.charAt(l++)];
}
if(left==right||right-left>i-l+1){
right = i+1;
left = l;
}
}
}
return s.substring(left,right);
}
}

class Solution {
public boolean isPalindrome(String s) {
StringBuilder str = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (Character.isLetterOrDigit(c)) {
str.append(Character.toLowerCase(c));
}
}
return str.toString().equals(new StringBuffer(str).reverse().toString());
}
}

class Solution {
public boolean validPalindrome(String s) {
for(int left = 0, right = s.length() - 1; left < right; left++, right--){
// 如果不相等,则分两种情况:删除左边的元素,或者右边的元素,再判断各自是否回文,满足一种即可。
if(s.charAt(left) != s.charAt(right))
return isPalindrome(s, left+1, right) || isPalindrome(s, left, right - 1);
}
return true;
}
// 判断字符串 s 的 [left, right] 是否回文
private boolean isPalindrome(String s, int left , int right){
while (left < right){
if (s.charAt(left++) != s.charAt(right--))
return false;
}
return true;
}
}

class Solution {
public int countSubstrings(String s) {
int n = s.length(), ans = 0;
for (int i = 0; i < 2 * n - 1; ++i) {
int l = i / 2, r = i / 2 + i % 2;
while (l >= 0 && r < n && s.charAt(l) == s.charAt(r)) {
--l;
++r;
++ans;
}
}
return ans;
}
}
边栏推荐
- Refinement of the four major collection frameworks: Summary of List core knowledge
- MySQL优化:从十几秒优化到三百毫秒
- matlab simulink欠驱动水面船舶航迹自抗扰控制研究
- CentOS7 - yum install mysql
- 信息系统项目管理师核心考点(五十五)配置管理员(CMO)的工作
- Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
- centos7安装mysql5.7
- mysql stored procedure
- MySQL forgot password
- 目标检测学习笔记
猜你喜欢

MySQL-Explain详解

DVWA shooting range environment construction

Unity Framework Design Series: How Unity Designs Network Frameworks

The monitoring of Doris study notes
![[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade](/img/af/7a2cdcc6535c04c508c9ddf9ee0cb2.png)
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade

Centos7 install mysql5.7

1. 获取数据-requests.get()

sql statement - how to query data in another table based on the data in one table

【mysql 提高查询效率】Mysql 数据库查询好慢问题解决

快速掌握并发编程 --- 基础篇
随机推荐
关于superset集成到自己的项目中
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
DVWA靶场环境搭建
MySQL (updating)
The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands
信息系统项目管理师核心考点(五十五)配置管理员(CMO)的工作
On-line monitoring system for urban waterlogging and water accumulation in bridges and tunnels
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
MySQL transaction isolation level, rounding
为什么要用Flink,怎么入门使用Flink?
Centos7 install mysql5.7 steps (graphical version)
Go language study notes - dealing with timeout problems - Context usage | Go language from scratch
SQL row-column conversion
.NET-6.WinForm2.NanUI learning and summary
基于web3.0使用钱包Metamask的三方登陆
The 15th day of the special assault version of the sword offer
The interviewer asked me TCP three handshake and four wave, I really
Minio upload file ssl certificate is not trusted
CentOS7 安装MySQL 图文详细教程
Paginate the list collection and display the data on the page