Fork me on GitHub

随笔分类 -  leetcode

摘要:这道题一开始是用栈 然后发现有点困难 然后直接用字符串切割 模拟栈的过程 ( flag ++ ) flag 当flag等于0 之后我们就会得到一个独立的部分 , 然后再把首尾两个括号去掉 即可 class Solution { public static String removeOuterPare 阅读全文
posted @ 2019-07-08 12:02 cznczai 阅读(144) 评论(0) 推荐(0)
摘要:能不能被5整除都看 看输入数字的最后一位是否为 0或者5 也就是最后一位是否能被整除 这道题很容易就溢出 所以我们仅包括最后几位即可 class Solution { public List prefixesDivBy5(int[] A) { List ans = new ArrayList(); 阅读全文
posted @ 2019-07-08 12:01 cznczai 阅读(119) 评论(0) 推荐(0)
摘要:输入n个整数,找出其中两个数,他们之和等于整数m 如果存在输出 true 不存在输出false 我这里用的是二分查找以及双指针 双指针 二分查找 阅读全文
posted @ 2019-07-08 11:05 cznczai 阅读(184) 评论(0) 推荐(0)
摘要:汉诺塔问题一直是我想解决的问题之一,汉诺塔也是让我感到编程的神奇之处,想了很久也领悟不了里面的奥秘。 附上灯哥教学视频https://www.bilibili.com/video/av9830115?from=search&seid=6226553387047262312 递归写法 n = N % 阅读全文
posted @ 2019-07-08 10:49 cznczai 阅读(123) 评论(0) 推荐(0)
摘要:题目, 我觉得最简单的方法就是用四个for循环把他解出来,一个一个枚举,用两个矩阵进行保存 public class Main { public void gameOfLife(int[][] board) { int length = board.length;// 得到数组的长 int wide 阅读全文
posted @ 2019-07-08 10:47 cznczai 阅读(271) 评论(0) 推荐(0)
摘要:如释重负 自己看了很多视频自己手写出自己的java版本的nqueen问题 get 以下是自己的解法: import java.util. ; import java.math. ; public class Main { public void Nqueen(int i, int n, int ar 阅读全文
posted @ 2019-07-08 10:41 cznczai 阅读(152) 评论(0) 推荐(0)
摘要:2 n 的原因 class Solution { int count; boolean bool_col[]; boolean bool_x[]; boolean bool_y[]; int n; public int totalNQueens(int _n) { n = _n ; count = 阅读全文
posted @ 2019-07-08 10:39 cznczai 阅读(130) 评论(0) 推荐(0)
摘要:本人解法 ~略麻烦 其他的解法 有点简单~~~~ 不用采用A~Z保存在一个数组中 最牛逼的一行解决 阅读全文
posted @ 2019-07-08 10:36 cznczai 阅读(204) 评论(0) 推荐(0)
摘要:本人的解法: public class Main { public int trap(int[] height) { // 统计雨水总数//temp登记最大值 int sum = 0; if (height.length != 0) { int temp = height[0]; int temp2 阅读全文
posted @ 2019-07-08 10:34 cznczai 阅读(146) 评论(0) 推荐(0)
摘要:本人先讲自己比较笨的 方法 package homework; public class Main { public String convert(String s, int numRows) { int length = s.length(), x = 0, y = 0; String arr[] 阅读全文
posted @ 2019-07-08 10:30 cznczai 阅读(274) 评论(0) 推荐(0)
摘要:https://www.bilibili.com/video/av46402848/ 考虑的方面要谨慎 用链表实现 层次遍历 阅读全文
posted @ 2019-07-07 22:24 cznczai 阅读(194) 评论(0) 推荐(0)
摘要:public class Main { //一开始我也想了很多方法 用另外一个矩阵帮忙保存 结果是错的 public void rotate(int[][] matrix) { int n = matrix.length; int top = 0, left = 0, right = n 1, bo 阅读全文
posted @ 2019-07-07 21:57 cznczai 阅读(441) 评论(0) 推荐(0)
摘要:这里运用了最小距离的算法 经典的动态规划 相同字符 左上角值加1 不相同字符 邻居三个取最小 注意点也要把"" 空字符串考虑进去 三个求最小可以改下为 Math.min(n, Math.min(m,l)) java class Solution { public int min(int n , in 阅读全文
posted @ 2019-07-07 21:35 cznczai 阅读(390) 评论(0) 推荐(0)
摘要:这道题仅仅是判断是否能解开数独 不要求解出来 java class Solution { public boolean isValidSudoku(char[][] board) { for(int i = 0 ; i j; k ) if(board[i][j] == board[i][k]) re 阅读全文
posted @ 2019-07-07 21:32 cznczai 阅读(234) 评论(0) 推荐(0)
摘要:class Solution { public int reverse(int x) { int flag = 1; int ans = 0; int temp = 0; if (x 0) { temp = x % 10; if (ans Integer.MAX_VALUE / 10 || (ans 阅读全文
posted @ 2019-07-07 21:20 cznczai 阅读(584) 评论(0) 推荐(0)
摘要:英语版 中文版 这道题思路跟一个up主一样 就是细节处理不是很好 ~~~~ x1 x2 x4 x8 而我没有导致超时 public int divide(int dividend, int divisor) { if (divisor == 0) return Integer.MAX_VALUE; 阅读全文
posted @ 2019-07-07 20:57 cznczai 阅读(334) 评论(0) 推荐(0)