lettcode java 常用方法

#数组排序
Arrays.sort(int[] a);
#数组拷贝 Arrays.copyOf(
int[] original, int newLength);
# 数组拷贝 System.arraycopy(Object src,
int srcPos,Object dest, int destPos,int length);
# 返回两数之中的最大值
Math.max(int a, int b);
# 是否数字
Character.isDigit(char ch);
# 整数的最大值
  Integer.MAX_VALUE;
 # 字符-字符为整数
 字符-'0';
 # 绝对值
 Math.abs(int a);

 

lettocde答题技巧:

  •   1.需要笔纸,画出图形,总结规律,然后设计成公式。

    例如:

    

       

           最长回文子串

 

abcdefg
slen =7

[start,end]
[0,] [1,] [2,] [3,] [4,] [5,] [6,] 
start = 0....7
end = start+len -1       # 帮助理解,思考整理思路是通过图形得出,并无此处。


len =1

[0,0] [1,1] [2,2] [3,3] [4,4] [5,5] [6,6]

len=2

[0,1]  [1,2] [2,3] [3,4] [4,5] [5,6] [6,7]

len = 3

[0,2] [1,3] [2,4] [3,5] [4,6] [5,7] 

len = 4

[0,3] [1,4] [2,5] [3,6] [4,7] 

len = 5

[0,4] [1,5] [2,6] [3,7] 

len = 6
[0,5] [1,6] [2,7]


总结公式 :
[start,end]
start = 1..slen
end = start+len -1

 

posted @ 2024-01-03 14:23  wq9  阅读(5)  评论(0)    收藏  举报