Fork me on GitHub

随笔分类 -  leetcode

摘要:递归解法 递推解法 阅读全文
posted @ 2019-08-13 20:48 cznczai 阅读(100) 评论(0) 推荐(0)
摘要:long l = 9223372036854775808; 后面是一个int 类型 的数 long l = 9223372036854775808L; 才是一个long类型的数 class Solution { public boolean isValidBST(TreeNode root) { r 阅读全文
posted @ 2019-08-13 16:59 cznczai 阅读(123) 评论(0) 推荐(0)
摘要:class Solution { public int movesToMakeZigzag(int[] nums) { int temp1[] = new int[nums.length]; int temp2[] = new int[nums.length]; for (int i = 0; i 阅读全文
posted @ 2019-08-10 17:52 cznczai 阅读(207) 评论(0) 推荐(0)
摘要:class Node { final static int the_maxsize = 26; Node[] list = new Node[the_maxsize]; char data; boolean isEnd = false; //用isEnd 代替isSelf 节约空间 } class 阅读全文
posted @ 2019-08-10 17:01 cznczai 阅读(91) 评论(0) 推荐(0)
摘要:暴力 class Solution { public int lengthOfLongestSubstring(String s) { int the_max = 0; HashSet hs = new HashSet(); for (int i = 0; i hs = new HashSet(); 阅读全文
posted @ 2019-08-10 15:41 cznczai 阅读(90) 评论(0) 推荐(0)
摘要:遍历中心点 然后像两边扩出去 class Solution { public String longestPalindrome(String s) { String ans =""; for(int i = 0 ; i =0&&y=0&&y 阅读全文
posted @ 2019-08-08 16:01 cznczai 阅读(125) 评论(0) 推荐(0)
摘要:class Solution { public int numUniqueEmails(String[] emails) { HashSet hs = new HashSet(); for (int i = 0; i hs = new HashSet(); for (String i : email 阅读全文
posted @ 2019-08-08 14:35 cznczai 阅读(169) 评论(0) 推荐(0)
摘要:今天项目里遇到以"." 、"\"、“|”分割字符串,直接用"." 、"\"、“|”无法分割,因为"." 、"\"、“|”是特殊字符,需要转义,"\\." 、"\\\"、“\\|”。 精简~ class Solution { public int compareVersion(String s1, S 阅读全文
posted @ 2019-08-08 12:45 cznczai 阅读(86) 评论(0) 推荐(0)
摘要:![](https://img2018.cnblogs.com/blog/1648545/201908/1648545-20190807170036698-2003229138.png) ``` class Solution { public String reverseWords(String s) { StringBuffer ans = new StringBuff... 阅读全文
posted @ 2019-08-07 23:46 cznczai 阅读(77) 评论(0) 推荐(0)
摘要:在美版leetcode上看到大神的思路,用质数表示26个字母,把字符串的各个字母相乘,这样可保证字母异位词的乘积必定是相等的。其余步骤就是用map存储,和别人的一致了。(这个用质数表示真的很骚啊!!!) 阅读全文
posted @ 2019-08-07 15:48 cznczai 阅读(136) 评论(0) 推荐(0)
摘要:public String countAndSay(int n) { String arr[] = new String[n + 1]; arr[1] = 1 + ""; for(int i = 2; i 阅读全文
posted @ 2019-08-05 23:38 cznczai 阅读(104) 评论(0) 推荐(0)
摘要:class Solution { public int movesToMakeZigzag(int[] nums) { int temp1[] = new int[nums.length]; int temp2[] = new int[nums.length]; for (int i = 0; i 阅读全文
posted @ 2019-08-04 15:04 cznczai 阅读(302) 评论(0) 推荐(0)
摘要:![](https://img2018.cnblogs.com/blog/1648545/201908/1648545-20190804150144609-456398695.png) ``` class Solution { public int maxProfit(int[] prices) { int maxPro = 0, tmp = 0; for (int i ... 阅读全文
posted @ 2019-08-04 15:02 cznczai 阅读(79) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-08-04 14:59 cznczai 阅读(215) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-08-04 14:58 cznczai 阅读(141) 评论(0) 推荐(0)
摘要:就是找一个由1组成的边界 暴力解决 找到这个边框 算出一个由多少个数 下面解法真的妙 class Solution { public int largest1BorderedSquare(int[][] grid) { int ans = 0; int n = grid.length; int m 阅读全文
posted @ 2019-08-02 16:31 cznczai 阅读(298) 评论(0) 推荐(0)
摘要:曼哈顿距离 class Solution { public String alphabetBoardPath(String target) { int x = 0, y = 0, nx = 0, ny = 0; StringBuffer ans = new StringBuffer(""); for 阅读全文
posted @ 2019-08-02 16:29 cznczai 阅读(252) 评论(0) 推荐(0)
摘要: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( 阅读全文
posted @ 2019-08-02 16:28 cznczai 阅读(230) 评论(0) 推荐(0)
摘要:有推文说这个东西 https://mp.weixin.qq.com/s?__biz=MzUyNjQxNjYyMg==&mid=2247486013&idx=2&sn=ad0211c2b25a1ac1ce10aa5bd95298ae&chksm=fa0e65bccd79ecaa62958b412f92 阅读全文
posted @ 2019-08-01 17:45 cznczai 阅读(411) 评论(0) 推荐(0)
摘要:可以用数组保存 然后每一个结点的值进行更改 https://www.bilibili.com/video/av49696612/?redirectFrom=h5 迭代法 递归 阅读全文
posted @ 2019-07-24 17:20 cznczai 阅读(110) 评论(0) 推荐(0)