随笔分类 - leetcode
摘要:long l = 9223372036854775808; 后面是一个int 类型 的数 long l = 9223372036854775808L; 才是一个long类型的数 class Solution { public boolean isValidBST(TreeNode root) { r
阅读全文
摘要:class Solution { public int movesToMakeZigzag(int[] nums) { int temp1[] = new int[nums.length]; int temp2[] = new int[nums.length]; for (int i = 0; i
阅读全文
摘要:class Node { final static int the_maxsize = 26; Node[] list = new Node[the_maxsize]; char data; boolean isEnd = false; //用isEnd 代替isSelf 节约空间 } class
阅读全文
摘要:暴力 class Solution { public int lengthOfLongestSubstring(String s) { int the_max = 0; HashSet hs = new HashSet(); for (int i = 0; i hs = new HashSet();
阅读全文
摘要:遍历中心点 然后像两边扩出去 class Solution { public String longestPalindrome(String s) { String ans =""; for(int i = 0 ; i =0&&y=0&&y
阅读全文
摘要:class Solution { public int numUniqueEmails(String[] emails) { HashSet hs = new HashSet(); for (int i = 0; i hs = new HashSet(); for (String i : email
阅读全文
摘要:今天项目里遇到以"." 、"\"、“|”分割字符串,直接用"." 、"\"、“|”无法分割,因为"." 、"\"、“|”是特殊字符,需要转义,"\\." 、"\\\"、“\\|”。 精简~ class Solution { public int compareVersion(String s1, S
阅读全文
摘要: ``` class Solution { public String reverseWords(String s) { StringBuffer ans = new StringBuff...
阅读全文
摘要:在美版leetcode上看到大神的思路,用质数表示26个字母,把字符串的各个字母相乘,这样可保证字母异位词的乘积必定是相等的。其余步骤就是用map存储,和别人的一致了。(这个用质数表示真的很骚啊!!!)
阅读全文
摘要:public String countAndSay(int n) { String arr[] = new String[n + 1]; arr[1] = 1 + ""; for(int i = 2; i
阅读全文
摘要:class Solution { public int movesToMakeZigzag(int[] nums) { int temp1[] = new int[nums.length]; int temp2[] = new int[nums.length]; for (int i = 0; i
阅读全文
摘要: ``` class Solution { public int maxProfit(int[] prices) { int maxPro = 0, tmp = 0; for (int i ...
阅读全文
摘要:class Solution { public int largest1BorderedSquare(int[][] grid) { int ans = 0; int n = grid.length; int m = grid[0].length; int[][] ud = new int[n][m
阅读全文
摘要:class Solution { public List largeGroupPositions(String S) { List ls = new LinkedList (); for (int i = 0; i l = new LinkedList(); int a = i; int b = i
阅读全文
摘要:就是找一个由1组成的边界 暴力解决 找到这个边框 算出一个由多少个数 下面解法真的妙 class Solution { public int largest1BorderedSquare(int[][] grid) { int ans = 0; int n = grid.length; int m
阅读全文
摘要:曼哈顿距离 class Solution { public String alphabetBoardPath(String target) { int x = 0, y = 0, nx = 0, ny = 0; StringBuffer ans = new StringBuffer(""); for
阅读全文
摘要:class Solution { public int tribonacci(int n) { int T0 = 0; int T1 = 1; int T2 = 1; int arr[] = new int [40]; arr[0] = 0; arr[1] = 1; arr[2] = 1; for(
阅读全文
摘要:有推文说这个东西 https://mp.weixin.qq.com/s?__biz=MzUyNjQxNjYyMg==&mid=2247486013&idx=2&sn=ad0211c2b25a1ac1ce10aa5bd95298ae&chksm=fa0e65bccd79ecaa62958b412f92
阅读全文
摘要:可以用数组保存 然后每一个结点的值进行更改 https://www.bilibili.com/video/av49696612/?redirectFrom=h5 迭代法 递归
阅读全文

浙公网安备 33010602011771号