12 2015 档案

摘要:12.7去西雅图微软on-site,等了两周终于等来了offer。看了地里很多面经,因为微软并没有签保密协议,今天来贡献一下。先说一下微软onsite体验真的很好,宾馆机票吃饭都安排的很好。一天给75刀饭补,本来以为都这样,后来谷歌onsite才知道谷歌只有30.我面的组是hololens,一共五轮... 阅读全文
posted @ 2015-12-29 15:05 Weizheng_Love_Coding 阅读(1419) 评论(0) 推荐(0)
摘要:经典动态规划public class Solution { public int coinChange(int[] coins, int amount) { int[] record = new int[amount + 1]; record[0] = 1; ... 阅读全文
posted @ 2015-12-29 14:21 Weizheng_Love_Coding 阅读(189) 评论(0) 推荐(0)
摘要:MS面试最后一轮就跪在number of island 1 了,痛心啊。bfs虽然能过lc,但是面试的时候得写出union find来才可以啊。public class Solution { private int[] array; private int[][] grid; pr... 阅读全文
posted @ 2015-12-15 07:04 Weizheng_Love_Coding 阅读(227) 评论(0) 推荐(0)
摘要:对每个房子bfs,找出每个房子到所有空地的距离。用一个record二维数组来记录每个空地上所有房子到该空地的距离和。同时用另一个二维数组记录每个空地能被几个房子访问到,来保证所有房子都可以到达的了该空地。public class Solution { public int shortestDi... 阅读全文
posted @ 2015-12-14 14:02 Weizheng_Love_Coding 阅读(547) 评论(0) 推荐(0)
摘要:思路借鉴了https://leetcode.com/discuss/73806/15-ms-java-solutionfor "cbacdcbc", we counts each letter's index:a----2b----1,6c----0,3,5,7d----4we go from a ... 阅读全文
posted @ 2015-12-14 06:38 Weizheng_Love_Coding 阅读(290) 评论(0) 推荐(0)
摘要:public class Solution { public List summaryRanges(int[] nums) { List result = new ArrayList(); int length = nums.length; int l... 阅读全文
posted @ 2015-12-14 05:37 Weizheng_Love_Coding 阅读(125) 评论(0) 推荐(0)
摘要:public class Solution { public int[] plusOne(int[] digits) { int carry = 1; int length = digits.length; List list = new ArrayL... 阅读全文
posted @ 2015-12-11 12:02 Weizheng_Love_Coding 阅读(139) 评论(0) 推荐(0)
摘要:刚从微软onsite回来,感觉要跪了。不过doesnt matter 继续刷题面谷歌很有意思的一道小题,很容易出错public class Solution { public int compareVersion(String version1, String version2) { ... 阅读全文
posted @ 2015-12-11 11:59 Weizheng_Love_Coding 阅读(118) 评论(0) 推荐(0)
摘要:二分搜索,边界条件要注意public class Solution { public List countSmaller(int[] nums) { List sorted = new ArrayList(); int length = nums.length; ... 阅读全文
posted @ 2015-12-07 08:55 Weizheng_Love_Coding 阅读(122) 评论(0) 推荐(0)
摘要:class TrieNode { // Initialize your data structure here. TrieNode[] child; boolean isWord; public TrieNode() { child = new TrieNode... 阅读全文
posted @ 2015-12-06 12:36 Weizheng_Love_Coding 阅读(132) 评论(0) 推荐(0)
摘要:public class Solution { public List wordBreak(String s, Set wordDict) { return helper(s, wordDict, new HashMap>()); } public List ... 阅读全文
posted @ 2015-12-06 12:19 Weizheng_Love_Coding 阅读(137) 评论(0) 推荐(0)
摘要:public class Solution { public String longestPalindrome(String s) { int length = s.length(); String result = ""; for (int i = ... 阅读全文
posted @ 2015-12-06 10:22 Weizheng_Love_Coding 阅读(144) 评论(0) 推荐(0)
摘要:public class Solution { public String longestPalindrome(String s) { int length = s.length(); String result = ""; for (int i = ... 阅读全文
posted @ 2015-12-06 09:47 Weizheng_Love_Coding 阅读(120) 评论(0) 推荐(0)
摘要:public class Solution { public String simplifyPath(String path) { String[] strs = path.split("/"); Stack stack = new Stack(); ... 阅读全文
posted @ 2015-12-06 08:05 Weizheng_Love_Coding 阅读(109) 评论(0) 推荐(0)
摘要:public class Solution { public int calculate(String s) { Stack stack = new Stack(); s = s.replace(" ", ""); int length = s.len... 阅读全文
posted @ 2015-12-06 07:35 Weizheng_Love_Coding 阅读(126) 评论(0) 推荐(0)
摘要:在网上看了一个超级精妙的解法public class Solution { public String multiply(String num1, String num2) { int length1 = num1.length(); int length2 = n... 阅读全文
posted @ 2015-12-06 06:31 Weizheng_Love_Coding 阅读(146) 评论(0) 推荐(0)
摘要:public class Solution { public TreeNode buildTree(int[] preorder, int[] inorder) { int length = preorder.length; if (length == 0) { ... 阅读全文
posted @ 2015-12-06 05:19 Weizheng_Love_Coding 阅读(134) 评论(0) 推荐(0)
摘要:用了treemap来维护左右关系,其实也可以不用,记录一个min的index就好。public class Solution { public List> verticalOrder(TreeNode root) { List> result = new ArrayList>()... 阅读全文
posted @ 2015-12-06 03:04 Weizheng_Love_Coding 阅读(323) 评论(0) 推荐(0)
摘要:这个题之前做过,实在没想出什么好方法,今天突然发现这个完全就是个有环链表找开始进入环的题目,真是相当精巧public class Solution { public int findDuplicate(int[] nums) { int slow = 0; int ... 阅读全文
posted @ 2015-12-05 14:31 Weizheng_Love_Coding 阅读(122) 评论(0) 推荐(0)
摘要:class MyStack { // Push element x onto stack. Queue queue = new LinkedList(); public void push(int x) { Queue q = new LinkedList(); ... 阅读全文
posted @ 2015-12-05 13:34 Weizheng_Love_Coding 阅读(126) 评论(0) 推荐(0)
摘要:public class Solution { public TreeNode invertTree(TreeNode root) { if (root == null) { return root; } TreeNode tmp... 阅读全文
posted @ 2015-12-05 13:29 Weizheng_Love_Coding 阅读(89) 评论(0) 推荐(0)
摘要:public class Solution { public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int area = (C - A) * (D - B) + (G -... 阅读全文
posted @ 2015-12-05 13:25 Weizheng_Love_Coding 阅读(92) 评论(0) 推荐(0)
摘要:public class Solution { public TreeNode buildTree(int[] inorder, int[] postorder) { return helper(inorder, postorder, 0, inorder.length - 1,... 阅读全文
posted @ 2015-12-05 09:49 Weizheng_Love_Coding 阅读(157) 评论(0) 推荐(0)
摘要:public class Solution { public String largestNumber(int[] nums) { int length = nums.length; Queue queue = new PriorityQueue(length, n... 阅读全文
posted @ 2015-12-05 09:19 Weizheng_Love_Coding 阅读(112) 评论(0) 推荐(0)
摘要:主要是一下步骤1.delete space in front of str2.check if str startsWith other characters3.check if str is positive4.check the end of str5.check if overflowpubl... 阅读全文
posted @ 2015-12-05 08:39 Weizheng_Love_Coding 阅读(144) 评论(0) 推荐(0)
摘要:第一个是普通二叉树,第二个是bstpublic class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if (root == null) { ... 阅读全文
posted @ 2015-12-05 08:00 Weizheng_Love_Coding 阅读(133) 评论(0) 推荐(0)
摘要:public class Solution { public int[][] generateMatrix(int n) { int level = (n + 1) / 2; int[][] result = new int[n][n]; int tm... 阅读全文
posted @ 2015-12-05 06:44 Weizheng_Love_Coding 阅读(145) 评论(0) 推荐(0)
摘要:上面是lc的单链表题目,下面我又自己加了个双向链表的情况public class Solution { public ListNode swapPairs(ListNode head) { if (head == null || head.next == null) { ... 阅读全文
posted @ 2015-12-05 03:54 Weizheng_Love_Coding 阅读(163) 评论(0) 推荐(0)
摘要:在无重复元素时,中间元素与首元素相等,表示一共只有两个元素,low与high各指向一个。由于while循环中限制的大小关系,因此返回nums[high]即为最小值。然而当存在重复元素时,该条件并不能表示一共只有low和high指向的两个元素,而是说明low指向的元素重复了,因此删除其一,low ++... 阅读全文
posted @ 2015-12-05 03:16 Weizheng_Love_Coding 阅读(135) 评论(0) 推荐(0)
摘要:public class Solution { public int[] productExceptSelf(int[] nums) { int length = nums.length; int[] result = new int[length]; ... 阅读全文
posted @ 2015-12-05 02:28 Weizheng_Love_Coding 阅读(126) 评论(0) 推荐(0)
摘要:public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int row = obstacleGrid.length; if (row == 0) { ... 阅读全文
posted @ 2015-12-04 16:42 Weizheng_Love_Coding 阅读(152) 评论(0) 推荐(0)
摘要:public class Solution { public void rotate(int[][] matrix) { int n = matrix.length; int count = (n + 1) / 2; for (int i = 0; i... 阅读全文
posted @ 2015-12-04 14:30 Weizheng_Love_Coding 阅读(114) 评论(0) 推荐(0)
摘要:判断四个数是否可能通过加减乘得到二十四, 可以使用括号,思路极其像Expression Add Operators, 区别是在处理乘号的时候,一种是没有括号的,和Expression Add Operators一样,一种是带有括号的,其实就是把乘号当作加号来计算public class Soluti... 阅读全文
posted @ 2015-12-04 12:45 Weizheng_Love_Coding 阅读(193) 评论(0) 推荐(0)
摘要:dp的方法比较简单就不写了。这里用分治法,对与一个数组,最大的子区间可以在left 到 mid这一段, 也可能划过mid, 也可能在mid 到 right, 所以分别求这三段,取最大的结果。求左右段最大的时候才用分治的想法。算法复杂度为o(nlogn)public class Solution { ... 阅读全文
posted @ 2015-12-04 11:53 Weizheng_Love_Coding 阅读(153) 评论(0) 推荐(0)
摘要:两种解法,第一个是利用了前序遍历递增的特点public class Solution { long count = Long.MIN_VALUE; public boolean isValidBST(TreeNode root) { if (root == null) { ... 阅读全文
posted @ 2015-12-04 09:42 Weizheng_Love_Coding 阅读(119) 评论(0) 推荐(0)
摘要:1 public class Solution { 2 public List> zigzagLevelOrder(TreeNode root) { 3 List> result = new ArrayList>(); 4 if (root == null)... 阅读全文
posted @ 2015-12-04 09:25 Weizheng_Love_Coding 阅读(133) 评论(0) 推荐(0)
摘要:第三次写了,一遍过/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(i... 阅读全文
posted @ 2015-12-04 09:08 Weizheng_Love_Coding 阅读(143) 评论(0) 推荐(0)
摘要:public class Solution { public int[] twoSum(int[] numbers, int target) { int left = 0; int right = numbers.length - 1; while (... 阅读全文
posted @ 2015-12-04 08:03 Weizheng_Love_Coding 阅读(115) 评论(0) 推荐(0)
摘要:public class Solution { private int result = Integer.MIN_VALUE; public int maxPathSum(TreeNode root) { helper(root); return result... 阅读全文
posted @ 2015-12-04 07:34 Weizheng_Love_Coding 阅读(109) 评论(0) 推荐(0)
摘要:public class Solution { public int minSubArrayLen(int s, int[] nums) { int p1 = 0; int p2 = 0; int length = nums.length; ... 阅读全文
posted @ 2015-12-04 07:34 Weizheng_Love_Coding 阅读(115) 评论(0) 推荐(0)
摘要:第一个是递归方法,第二个是非递归方法public class Solution { public boolean isSymmetric(TreeNode root) { if (root == null) { return true; } ... 阅读全文
posted @ 2015-12-04 07:26 Weizheng_Love_Coding 阅读(117) 评论(0) 推荐(0)
摘要:public class Solution { public int findPeakElement(int[] nums) { int left = 0; int right = nums.length - 1; while (left + 1 n... 阅读全文
posted @ 2015-12-03 15:44 Weizheng_Love_Coding 阅读(123) 评论(0) 推荐(0)
摘要:public class ZigzagIterator { private List v1; private List v2; private int p1; private int p2; private boolean flg = true; publ... 阅读全文
posted @ 2015-12-03 13:44 Weizheng_Love_Coding 阅读(128) 评论(0) 推荐(0)
摘要:public class Solution { List result = new ArrayList(); public List letterCombinations(String digits) { if (digits.length() == 0) { ... 阅读全文
posted @ 2015-12-03 10:13 Weizheng_Love_Coding 阅读(119) 评论(0) 推荐(0)
摘要:public class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { int carry = 0; ListNode result = new ListNode(0); ... 阅读全文
posted @ 2015-12-03 09:50 Weizheng_Love_Coding 阅读(114) 评论(0) 推荐(0)
摘要:思路和ugly2一样,不过是变成了一组factor,用一个priority求出每次最小的,同时维护一个conut数组,记录每个factor走的次数有一个500000的过不了,超限了,无耻的写了一行作弊的代码public class Solution { public int nthSuperU... 阅读全文
posted @ 2015-12-03 09:20 Weizheng_Love_Coding 阅读(204) 评论(0) 推荐(0)
摘要:public class Solution { public int removeElement(int[] nums, int val) { if (nums.length == 0) { return 0; } int lef... 阅读全文
posted @ 2015-12-03 03:04 Weizheng_Love_Coding 阅读(124) 评论(0) 推荐(0)
摘要:public class Solution { public String convert(String s, int numRows) { if (numRows == 1) { return s; } int flg = 0;... 阅读全文
posted @ 2015-12-03 02:09 Weizheng_Love_Coding 阅读(125) 评论(0) 推荐(0)
摘要:public class LRUCache { HashMap map = new HashMap(); ListNode start; ListNode end; int capacity; int cur_size; public LRUCache(int c... 阅读全文
posted @ 2015-12-03 01:59 Weizheng_Love_Coding 阅读(121) 评论(0) 推荐(0)
摘要:第一个是用了hashmap, 第二个是在每个结点后面加一个新的结点public class Solution { public RandomListNode copyRandomList(RandomListNode head) { if (head == null) { ... 阅读全文
posted @ 2015-12-02 15:47 Weizheng_Love_Coding 阅读(139) 评论(0) 推荐(0)
摘要:public class Solution { public List getSkyline(int[][] buildings) { List height = new ArrayList(); List result = new ArrayList(); ... 阅读全文
posted @ 2015-12-02 15:37 Weizheng_Love_Coding 阅读(152) 评论(0) 推荐(0)
摘要:单纯的dfs,感觉应该有更好的办法public class Solution { public void solveSudoku(char[][] board) { helper(board); } public boolean helper(char[][] boa... 阅读全文
posted @ 2015-12-02 14:26 Weizheng_Love_Coding 阅读(143) 评论(0) 推荐(0)
摘要:public class Solution { public void connect(TreeLinkNode root) { if (root == null) { return; } TreeLinkNode pre = r... 阅读全文
posted @ 2015-12-02 11:58 Weizheng_Love_Coding 阅读(149) 评论(0) 推荐(0)
摘要:之前写了个很复杂的办法,后来参考网上思路,觉得这个是最简便的写法了public class Solution { public String numberToWords(int num) { String[] first = "Zero One Two Three Four Fi... 阅读全文
posted @ 2015-12-02 11:42 Weizheng_Love_Coding 阅读(156) 评论(0) 推荐(0)
摘要:public class Solution { public void rotate(int[] nums, int k) { int length = nums.length; k = k % length; reverse(nums, 0, len... 阅读全文
posted @ 2015-12-02 08:26 Weizheng_Love_Coding 阅读(130) 评论(0) 推荐(0)
摘要:public class Solution { public List spiralOrder(int[][] matrix) { List result = new ArrayList(); int row = matrix.length; if (... 阅读全文
posted @ 2015-12-02 08:17 Weizheng_Love_Coding 阅读(118) 评论(0) 推荐(0)
摘要:public class Solution { private char[][] board; private List result = new ArrayList(); public List findWords(char[][] board, String[]... 阅读全文
posted @ 2015-12-02 05:16 Weizheng_Love_Coding 阅读(167) 评论(0) 推荐(0)
摘要:动规public class Solution { public boolean isInterleave(String s1, String s2, String s3) { int length1 = s1.length(); int length2 = s2.... 阅读全文
posted @ 2015-12-02 04:38 Weizheng_Love_Coding 阅读(107) 评论(0) 推荐(0)
摘要:这个题目主要是需要处理两个数长度不一样的情况,有两个解决办法。我是采用递归,把长的那一段与carray再加。也可以把短的前面补0.public class Solution { public String addBinary(String a, String b) { int p... 阅读全文
posted @ 2015-12-02 03:16 Weizheng_Love_Coding 阅读(120) 评论(0) 推荐(0)
摘要:public class Solution { public String countAndSay(int n) { if (n == 1) { return "1"; } String str = "1"; for... 阅读全文
posted @ 2015-12-01 16:11 Weizheng_Love_Coding 阅读(127) 评论(0) 推荐(0)
摘要:public class Solution { public String longestCommonPrefix(String[] strs) { if (strs.length == 0) { return ""; } int... 阅读全文
posted @ 2015-12-01 15:55 Weizheng_Love_Coding 阅读(126) 评论(0) 推荐(0)
摘要:public class Solution { public boolean containsNearbyDuplicate(int[] nums, int k) { HashMap map = new HashMap(); for (int i = 0; i < ... 阅读全文
posted @ 2015-12-01 15:48 Weizheng_Love_Coding 阅读(129) 评论(0) 推荐(0)
摘要:public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { ListNode dummy = new ListNode(0); dummy.next = head;... 阅读全文
posted @ 2015-12-01 15:35 Weizheng_Love_Coding 阅读(102) 评论(0) 推荐(0)
摘要:public class Solution { boolean result = true; public boolean isBalanced(TreeNode root) { helper(root); return result; } pub... 阅读全文
posted @ 2015-12-01 15:28 Weizheng_Love_Coding 阅读(109) 评论(0) 推荐(0)
摘要:public class Solution { public int minDepth(TreeNode root) { if (root == null) { return 0; } Queue queue = new Link... 阅读全文
posted @ 2015-12-01 15:25 Weizheng_Love_Coding 阅读(128) 评论(0) 推荐(0)
摘要:public class Solution { public boolean canAttendMeetings(Interval[] intervals) { Arrays.sort(intervals, new Comparator() { public... 阅读全文
posted @ 2015-12-01 15:06 Weizheng_Love_Coding 阅读(132) 评论(0) 推荐(0)
摘要:public class Solution { public boolean isAnagram(String s, String t) { char[] first = s.toCharArray(); Arrays.sort(first); cha... 阅读全文
posted @ 2015-12-01 15:03 Weizheng_Love_Coding 阅读(119) 评论(0) 推荐(0)
摘要:public class Solution { public int titleToNumber(String s) { int result = 0; int tmp = 1; for (int i = s.length() - 1; i >= 0;... 阅读全文
posted @ 2015-12-01 15:01 Weizheng_Love_Coding 阅读(107) 评论(0) 推荐(0)
摘要:public class Solution { public int longestConsecutive(int[] nums) { HashSet set = new HashSet(); for (int num : nums) { se... 阅读全文
posted @ 2015-12-01 10:02 Weizheng_Love_Coding 阅读(110) 评论(0) 推荐(0)
摘要:public class Solution { private int result = 0; public int longestConsecutive(TreeNode root) { if (root == null) { return 0; ... 阅读全文
posted @ 2015-12-01 09:54 Weizheng_Love_Coding 阅读(142) 评论(0) 推荐(0)
摘要:public class Solution { public int lengthOfLIS(int[] nums) { int length = nums.length; List record = new ArrayList(); for (int... 阅读全文
posted @ 2015-12-01 09:30 Weizheng_Love_Coding 阅读(126) 评论(0) 推荐(0)
摘要:public class Solution { public boolean wordPatternMatch(String pattern, String str) { return helper(pattern, str, new HashMap(), new HashMap... 阅读全文
posted @ 2015-12-01 09:01 Weizheng_Love_Coding 阅读(142) 评论(0) 推荐(0)
摘要:用的dfs,但是感觉这个方法应该不是最优的,否则这个题目不应该是hardpublic class Solution { int up = Integer.MAX_VALUE; int low = Integer.MIN_VALUE; int left = Integer.MAX_V... 阅读全文
posted @ 2015-12-01 08:08 Weizheng_Love_Coding 阅读(149) 评论(0) 推荐(0)
摘要:相当tricky的一道题目,我怀疑在面试的时候有人能在45分钟想出来,我参考了一下https://leetcode.com/discuss/72215/java-dp-solution-with-detailed-explanation-o-n-3这个人的思路。public class Soluti... 阅读全文
posted @ 2015-12-01 07:07 Weizheng_Love_Coding 阅读(699) 评论(0) 推荐(0)
摘要:public class Solution { public int minCostII(int[][] costs) { int n = costs.length; if (n == 0) { return 0; } ... 阅读全文
posted @ 2015-12-01 07:04 Weizheng_Love_Coding 阅读(143) 评论(0) 推荐(0)
摘要:public class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummy = new ListNode(0); dummy.next = head;... 阅读全文
posted @ 2015-12-01 05:12 Weizheng_Love_Coding 阅读(144) 评论(0) 推荐(0)
摘要:public class Solution { public void connect(TreeLinkNode root) { if (root == null) { return; } Queue queue = new Li... 阅读全文
posted @ 2015-12-01 03:18 Weizheng_Love_Coding 阅读(137) 评论(0) 推荐(0)
摘要://DFS,没有剪枝public class Solution { List> result = new ArrayList>(); public List> combinationSum3(int k, int n) { helper(k, n, 0, new Array... 阅读全文
posted @ 2015-12-01 02:02 Weizheng_Love_Coding 阅读(137) 评论(0) 推荐(0)