随笔分类 - 算法
刷题以及算法知识
摘要:二,RoundC import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import
阅读全文
摘要:由于找实习过程中,非常的顺利,2个月的时间拿下了23个offer。师弟师妹们吵着要面筋,决定在本文陆陆续续记录找工作的过程和心得。 1,实习部分: 最后决定去微软实习,为了校招冲击硅谷。 实习面筋总结传送门:https://bbs.byr.cn/#!article/Job/1855677(注意看我I
阅读全文
摘要:本文使用方法:所有题目,只需要把标题输入lintcode就能找到。主要是简单的剖析思路以及不能bug-free的具体细节原因。 第九周:图和搜索。 1, Clone Graph(克隆图) (1)答案和思路:首先用list来记录有哪些图,然后对于每一个节点都要新建。用map来做新旧节点的一一对应,以便
阅读全文
摘要:1,自己写的又长又臭的代码,也能AC,但是太丑了。主要是通过二进制来算。public static int addAB(int a, int b){ int res = 0; String str1 = Integer.toBinaryString(a); ...
阅读全文
摘要:思路:1,先给出LTE的代码: public static int countNumberOf2s(int n) { // write code here int res = 0; for(int i = 0; i 0){ i...
阅读全文
摘要:思路:注意一下,找猜中的时候什么都不用做,直接统计,找伪猜中也是先不管,然后再把结果减去猜中即可。public static int[] calcResult(String a, String b){ int[] res = new int[2]; Str...
阅读全文
摘要:牛客网的在线题。思路,比较简单。就是判断一下是否有连起来的1. public static boolean checkWon(int[][] board){ boolean res = false; for(int i = 0; i < 3;i++){ ...
阅读全文
摘要:思路,其实这题easy,就是看多少个5.答案: public static int getFactorSuffixZero(int n) { // write code here int res = 0; while(n != 0){ ...
阅读全文
摘要:思路:借助max公式就可以了。max(x,y)=0.5*(x+y+|x-y|)注意:1,结尾要加(int)。答案:max(x,y)=0.5*(x+y+|x-y|)View Code
阅读全文
摘要:思路:比较easy。就是借助hashset让他有序然后就能够比较节省时间了。答案: public static int[] getRankOfNumber(int[] a, int n){ int[] res = new int[n]; HashSet ha...
阅读全文
摘要:1,牛客网第一题:这其实跟找最长递增子序列是一个东西。注意的地方是,返回的是最大的dp,而不是dp[N-1]。答案:public static int getHeight(int[] men, int n) { // write code here int res = 0...
阅读全文
摘要:思路,一旦提到查找就要想到二分查找。 public static int[] findElement(int[][] a, int n, int m, int key) { // write code here int[] res = new int[2]; ...
阅读全文
摘要:注意,1,"" 和 " "。是不同的,空字符串指的是"";2,注意String的compareTo。小于是指 left && a[mid] == "") { mid--; } if(key.equals...
阅读全文
摘要:思路,这道题用二分,唯一的不同就是,1,a[left]= a[left]){ right = mid -1; } else{ left = mid + 1; ...
阅读全文
摘要:这道题主义的就是,要利用数组自带的sort函数。此外,注意,利用hash来判断是否出现了。 public static ArrayList sortStrings(String[] str, int n) { // write code here Arra...
阅读全文
摘要:1,牛客网的解题思路:其实这就是求一个最长的递增子序列。 以某一个箱子结尾的最大高度=放在它上面的所有类型中高度最大的那个+他自己的高度。import java.util.*; public class Box { public int getHeight(int[] w, int[] l,...
阅读全文
摘要:思路:首先写一个检查能不能摆的函数。boolean checkValid(int[] columns,int row1, int column1);意思是row1行摆在column1列可不可以。然后是place函数。第一个参数row表示现在摆第几行。第一行可以摆n次位置,然后往下也是8ci。也就是相...
阅读全文
摘要:这道题比较简单,就是通过从后往前复制大的就可以了。最后比较注意的就是如果B还没复制完要记得接着复制。import java.util.Arrays;public class Solution{ public static void main(String[] args){ int...
阅读全文
摘要:这道题卡了一天。要想AC非常难。1,第一个解决办法,优化暴力:public class Coins { public static int countWays(int n){ int num25 = n / 25; long res = 0; for(int i = 0; i ...
阅读全文
摘要:----思路:利用三个队列,一个存3,一个存5,一个存7.然后,3*3的都放第一个。然后3*5,5*5的放第二个。然后,3*7,5*7,7*7的都放第三个。答案: public static int findKth(int k){ ArrayList res = new Arra...
阅读全文

浙公网安备 33010602011771号