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

浙公网安备 33010602011771号