Fork me on GitHub

随笔分类 -  leetcode

摘要:本人想法比较简单 阅读全文
posted @ 2019-07-08 12:59 cznczai 阅读(93) 评论(0) 推荐(0)
摘要:递归解决方法 其他人解法也是大同小异 int climbStairs(int n){ int x1=0,x2=1; int i; int sum; for(i=1;i memo = new HashMap(); public int climbStairs(int n) { if(n 阅读全文
posted @ 2019-07-08 12:57 cznczai 阅读(108) 评论(0) 推荐(0)
摘要:public int findJudge(int N, int[][] trust) { if( N==1 && trust.length==0) { return 1; } if (trust.length != 0) { // arr用于投票记录 int arr[] = new int[1000 阅读全文
posted @ 2019-07-08 12:55 cznczai 阅读(166) 评论(0) 推荐(0)
摘要:题目介绍得有点问题 过程是将一组数组进行处理 处理后再返回有几个不同的项 class Solution { public int removeDuplicates(int[] nums) { if(nums.length==0) return 0; int i=0; for(int j=0; j 阅读全文
posted @ 2019-07-08 12:54 cznczai 阅读(98) 评论(0) 推荐(0)
摘要:思路导图 先用几个二维数组保存 abcd 用ASCII码保存在二维数组中 HashMap 一开始写不出来 卡了很久 class Solution { public List commonChars(String[] A) { List result = new ArrayList(); List l 阅读全文
posted @ 2019-07-08 12:52 cznczai 阅读(177) 评论(0) 推荐(0)
摘要:package leetcode; import java.util.Stack; public class Main { public boolean isValid(String S) { //一些前提条件 if (S == null || S.length() == 0) return tru 阅读全文
posted @ 2019-07-08 12:50 cznczai 阅读(179) 评论(0) 推荐(0)
摘要:动态规划解法 用两个for 阅读全文
posted @ 2019-07-08 12:44 cznczai 阅读(146) 评论(0) 推荐(0)
摘要:emmm 很遗憾超时间了 优化后 再次修改 分成两步 一步是判断是否已经是两个连接同样的字母在一起了 ,另一步则是添加 第二种不会超时 阅读全文
posted @ 2019-07-08 12:38 cznczai 阅读(229) 评论(0) 推荐(0)
摘要:感觉挺简单的 结果掉坑了 超时警告 public int countPrimes(int n) { int sum = 0; int[]arr = new int [n]; for(int i = 2 ;i 阅读全文
posted @ 2019-07-08 12:31 cznczai 阅读(163) 评论(0) 推荐(0)
摘要:这道题采用的是hashset 如果重复的话就return true 方法不难 public boolean containsDuplicate(int[] nums) { HashSet hs = new HashSet(); for(int i = 0 ;i 阅读全文
posted @ 2019-07-08 12:29 cznczai 阅读(172) 评论(0) 推荐(0)
摘要:这道题我的做法是进行排序 从小到大 取以一个数取反 再进行排序取反 每一次取的数都是最小的 如 10 变 10 排序 取第一个数 class Solution { public int largestSumAfterKNegations(int[] A, int K) { Arrays.sort(A 阅读全文
posted @ 2019-07-08 12:28 cznczai 阅读(136) 评论(0) 推荐(0)
摘要:![](https://img2018.cnblogs.com/blog/1648545/201907/1648545-20190708122609842-18595928.png) ``` public int clumsy(int N) { //12 = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1 //arr存放数据 //sum 先取第一个数 ... 阅读全文
posted @ 2019-07-08 12:27 cznczai 阅读(191) 评论(0) 推荐(0)
摘要:![](https://img2018.cnblogs.com/blog/1648545/201907/1648545-20190708122454608-120106475.png) ``` class ListNode { int val; ListNode next; ListNode (int val) {this.val = val;} } class MyLin... 阅读全文
posted @ 2019-07-08 12:26 cznczai 阅读(122) 评论(0) 推荐(0)
摘要:下面是我的算法 一开始采用的是while(ln2 != null && ln1 != null) 结果答案就是解不出 然后采用下面更加啰嗦的 就好了 ~~~~ 简化版: 阅读全文
posted @ 2019-07-08 12:25 cznczai 阅读(154) 评论(0) 推荐(0)
摘要:自己的方法不适用性太差了 因为要另外处理0; 所以不建议采用 import java.util.Scanner; class Solution { public int bitwiseComplement(int N) { String str = ""; int sum = 0 ; if(N == 阅读全文
posted @ 2019-07-08 12:23 cznczai 阅读(441) 评论(0) 推荐(0)
摘要:对于这种题目 第一反应是看看怎么去枚举所有情况 然后看所有合适的情况 所对应最小的船载重量 根据提示判断 必定会超时 第一次接触这种题目 自己还不够熟练 不知道根据提示采用二分查找 一个一个船载重量的值进行判断 public class Solution { public int shipWithi 阅读全文
posted @ 2019-07-08 12:14 cznczai 阅读(175) 评论(0) 推荐(0)
摘要:这道题就是找自己大的那个数就好 简单的解法 后面增加用栈解的方法 class Solution { public int[] nextLargerNodes(ListNode head) { ArrayList al = new ArrayList(); while(head!=null) {al. 阅读全文
posted @ 2019-07-08 12:07 cznczai 阅读(340) 评论(0) 推荐(0)
摘要:这道题不难 按照int正常解答的话 后面会出现溢出的情况 所以要想想怎么解决溢出问题 可被5整除的数 最后一位一定是0 或者是 5 才可以被整除 而前面的部分是没有意义的数 所以我们只留下最后一位就行 用%10 class Solution { public List prefixesDivBy5( 阅读全文
posted @ 2019-07-08 12:06 cznczai 阅读(186) 评论(0) 推荐(0)
摘要:贪心算法:如果绕不过某个零的话 就会return false 如果能绕过去 就一定能达到对面 阅读全文
posted @ 2019-07-08 12:05 cznczai 阅读(101) 评论(0) 推荐(0)
摘要:这道题题意不难 但是不用循环或者递归的话 还是有点难度的 第二种比较有意思 如果只有一个1 其他都是0 说明是3的幂 三进制 阅读全文
posted @ 2019-07-08 12:03 cznczai 阅读(101) 评论(0) 推荐(0)