当前位置:网站首页>leet面试150
leet面试150
2022-08-10 17:19:00 【无敌菜鸟ya】
5、最长回文子串
class Solution {
public String longestPalindrome(String s) {
if(s==null || s.length()==0) return null;
char[] ss=s.toCharArray();
int resi=0,resj=0,reslen=0,len=s.length();
boolean[][] dp=new boolean[len][len];
for(int i=len-1;i>=0;--i){ //这里要注意一定是从下到上,从左到右!!!
for(int j=i;j<len;++j){
if(ss[i]==ss[j]){
if(j-i<=1 || dp[i + 1][j - 1]) //两种情况
dp[i][j]=true;
}
if(dp[i][j]==true && j-i+1>reslen){
resi=i;
resj=j;
reslen=j-i+1;
}
}
}
return s.substring(resi,resj+1);
}
}
7、整数反转
class Solution {
public int reverse(int x) {
int res = 0;
while(x != 0) {
int temp = res * 10 + x % 10;
x /= 10;
if (temp / 10 != res) { //溢出判断的一个很妙的条件
return 0;
}
res = temp;
}
return res;
}
}
11、盛水最多的容器
https://leetcode.cn/problems/container-with-most-water/
class Solution {
public int maxArea(int[] height) {
int len=height.length;
if(len==0) return 0;
int res=0;
for(int i=0,j=len-1;i<j;){
res=Math.max(res,(j-i)*Math.min(height[i],height[j]));
if(height[i]<height[j]) ++i;
else --j;
}
return res;
}
}
未完待续!
边栏推荐
猜你喜欢
- [email protected] 7.6"/>
Oracle Install [email protected] 7.6
PC软件问题二[Win10系统将UltraEdit添加到右键菜单的方法]
Trie字典树
深度学习培训二笔记
Embedded Development: Embedded Basics - Mapping Peripherals Using Arrays of Pointers
挑战用五行代码轻松集成登录系统,实现单点登录
Talk about cloud native data platform
Pytorch GPU模型推理时间探讨
SQL优化的魅力!从 30248s 到 0.001s
【图像去雾】基于颜色衰减先验的图像去雾附matlab代码
随机推荐
mysql定义存储过程
ROBOTSTXT_OBEY[通俗易懂]
leetcode:340.至多包含K个不同字符的最长子串
kuangbin专题一 简单搜索
神经网络有哪些激活函数,卷积神经网络有哪些
事务的隔离级别,MySQL的默认隔离级别
skywalking vulnerability learning
分类常用的神经网络模型,深度神经网络主要模型
R语言使用oneway.test函数执行单因素方差分析(One-Way ANOVA)、使用数据集的子集数据进行单因素方差分析(subset函数筛选数据子集)
Pytorch GPU模型推理时间探讨2——显卡warm up
JNDI and RMI, LDAP
Polling and the principle of webSocket and socket.io
MySQL增加字段SQL语句
BalsnCTF2021
本周四晚19:00知识赋能第六期第5课丨OpenHarmony WiFi子系统
#夏日挑战赛#【ELT.ZIP】啃论文俱乐部——学术科研方法论沉淀辑
redis分布式锁
R语言patchwork包将多个可视化结果组合起来、plot_annotation函数以及tag_level参数将组合图用大写字母进行顺序编码、为组合图的标签添加自定义后缀信息(suffix)
百日刷题挑战--错题01day
等保2.0一个中心三重防护指的是什么?如何理解?