- 博客(137)
- 收藏
- 关注
原创 Hi, I'm Fred
Hi my name is Fred. I'm now a graduate student major in Computer Science at University of Toronto. I spend half an year in Pittsburgh as an graduate student major in Information System at Carnegie Mel
2016-01-17 05:38:54 583
原创 【Leetcode】Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, ret
2016-09-12 03:38:36 418
原创 【Leetcode】Largest Divisible Subset
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.If there are multiple solution
2016-09-11 02:34:59 371
原创 【Leetcode】Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** * Def
2016-04-01 09:39:00 411
原创 【Leetcode】Reverse Words in a String II
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.The input string does not contain leading or trailing spaces and the words are alway
2016-04-01 03:09:30 424
原创 学了一招合并几万个文件
之前都知道合并,单纯的 cat * > merged_file 就可以了,但是今天要出了几万个文件就会报错,所以我研究了一下怎么办。第一个人说可以利用xargs,但是失败了。。。我也不知道为什么,知道的朋友告诉我一下,我看着还挺有道理的:ls | xargs -n 32 -P 8 cat >> ../saved_output第二个这个work了,非常精彩: ls | whi
2016-02-25 10:04:17 401
原创 【Leetcode】House Robber II
After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at this place are arranged in a ci
2016-02-22 04:29:46 375
原创 【Leetcode】House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house
2016-02-19 14:11:52 354
原创 【Leetcode】Binary Tree Level Order Traversal I/II AND Binary Tree Zigzag Level Order Traversal
看这篇文章的朋友们建议先看一下我的上一篇文章,讲的非常清楚我们面对“level”的问题的时候我们要怎么写代码处理,再强调一次每次BFS在里面的时候,一定要手写int size= queue.size(),因为queue一直是dynamic的!!!ok,第一二问的Binary Tree Level Order Traversal 其实是一样的。一、Given a binary
2016-02-12 07:45:53 357
原创 【Leetcode】Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1
2016-02-12 06:09:57 312
原创 Populating Next Right Pointers in Each Node I, II
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.
2016-02-09 04:36:04 303
原创 【Leetcode】Two Problems: Convert Sorted Array/List to Binary Search Tree
First let's try easier one:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.The logic is very simple: Every time you find the middle element and p
2016-02-08 07:56:11 485
原创 【Leetcode】Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.————————————————————————最近准备开始
2016-02-08 07:11:50 321
原创 Sum up - Java Thread Interview Questions (Updating)
Java Thread Interview Questions1. Difference between Thread and Process in Java?Thread is subset of Process, in other words one processcan contain multiple threads. Two process runs on differe
2016-02-06 12:18:26 374
原创 Sum up - Linux Interview Questions (Updating)
Linux / Shell interview questions 1. Write a command that will look for files with anextension “c”, and has the occurrence of the string “apple” in it.Find ./ -name “*.c” | xargs grep –i “ap
2016-02-06 10:50:07 439
原创 Dynamic Programming for Brother Du
Let's see an example to understand what is dynamic programming.Alice is located in the North-West (Top-Left) block of her city, which has the form of a gird of NxNNxN blocks. On each block the
2016-02-05 11:33:18 629 1
原创 Greatest Common Divisor 最大公约数 O(n)
不废话,直接上代码package testAndfun;//great common divisorpublic class gcd { public static void main(String[] args){ gcd g = new gcd(); int[] input = {16,64,26,78}; System.out.println(g.getGCD(inp
2016-02-04 07:13:04 533
原创 LFU Cache
与LRU不同LFU关注与出现的频率,然后想自己写一个,区别在于:如果是LRU,假如capacity是2:输入是ABCBBBBBBCAA,那么最后会剩下的是C和A在缓存里。但是如果是LFU,capacity也是2:输入是ABCBBBBBBCAA,最后剩下的是[A,B],因为B出现的频率高。也就是说就算之前因为频率低被淘汰了,后面又出现了也要再回来。所以我想的设计方案是,整个LFUCach
2016-02-04 06:03:01 2316
原创 Merge Two Linked List
Given 1-3-5-6-8, 2-4-9, you want to merge to 1-2-3-4-5-6-8-9.My solution is very naive solution that actually build a new linkedlist, require space O(n).public ListNode mergeTwoLists(ListNode l1,
2016-02-03 23:36:34 340
原创 K Closest Points
Given (0,0) as the centre and an array containing pair of coordinate such that (1,1)(-2,4)(3,4)(-11,5)...(x,y).If ask you return k closest points, how would you do it?import java.util.
2016-02-03 12:21:32 511
原创 Reverse Half LinkedList
1-2-3-4-5-6 into 1-2-3-6-5-4 or 1-2-3-4-5 into 1-2-5-4-3I took advantage of reversing a linkedlist.I provided main func and prinf func.package testAndfun;public class reverseHalfLinkedList {
2016-02-03 11:08:07 346
原创 【Leetcode】Longest palindrome substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.——————————————————
2016-02-03 08:40:14 412
原创 A few very crucial DATA STRUCTURE
0. queue 这次好好看之前,我觉得我一直对queue简直就是一知半解。首先queue与stack并不是对称的,在java里。stack可以直接new, 而queue只是一个接口,上张图就明白了。一眼明了,我觉得要想闹明白,最好就是去看源码,去看从最上面怎么一步一步继承下来的,每一个数据结构自己的特点又都是什么。对于queue的方法,这里有必要讲一下:这里简单对其重
2016-02-03 08:22:11 370
原创 碰到一道经典的,Max Min Path
题目大概是这个意思:给定一个n*m的数组,找到每一条能从左上角探索到左下角的path,然后每一条path里找到最小值,所有这些最小值合在一起,看最大值是哪个。举个例子:[8, 4, 7][6, 5, 9]有3条path:8-4-7-9 min: 48-4-5-9 min: 48-6-5-9 min: 5return: 5这道题看地理大家激烈的讨论,说拿D
2016-02-02 13:05:39 555
原创 【Leetcode】Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window
2016-02-02 07:15:20 224
原创 【Leetcode】Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in
2016-02-02 06:19:22 305
原创 【Leetcode】Rectangle Area && Classic Prob: Overlap Rectangle
Overlap Rectangle:这道题的关键在于:不要去考虑overlap有几种情况,虽然肯定能做出来,但是要考虑的情况太多了,不如就考虑一定不会overlap的情况。无非就是两个rectangle x轴离的太远或者y轴离得太远:public class overlapRect { public static void main(String[] args){ rect
2016-02-02 06:04:27 494
原创 【Deep Learning】Review of Designing Deep Networks for Surface Normal Estimation
DesigningDeep Networks for Surface Normal Estimationlink:http://www.cs.cmu.edu/~dfouhey/deep3d/deep3d.pdf________________________________________________1. Summary of thePaperBy inj
2016-02-02 04:40:45 1069
原创 【Deep Learning】Review of Stereo Matching by Training a Convolutional Neural Network to Compare Image
Stereo Matching by Training a Convolutional Neural Network to Compare ImageLink: http://arxiv.org/abs/1510.05970Code: https://github.com/jzbontar/mc-cnn____________________________________
2016-02-02 04:39:00 1993
原创 【Leetcode】Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get
2016-02-01 15:08:16 349
原创 【Leetcode】Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?——————————————————————Question is not hard at all.
2016-02-01 11:57:00 350
原创 【Leetcode】Reverse LinkedList
太经典的题目了,我就不废话了,只是为了po这个我非常obsessed的方法:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public c
2016-02-01 05:47:42 305
原创 【Leetcode】Subsets
Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For
2016-02-01 03:49:15 382
原创 【Leetcode】Maximum Size Subarray Sum Equals k
Example 1:Given nums = [1, -1, 5, -2, 3], k = 3,return 4. (because the subarray [1, -1, 5, -2] sums to 3 and is the longest)Example 2:Given nums = [-2, -1, 2, 1], k = 1,return 2. (
2016-02-01 03:30:57 625
原创 【Leetcode】Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th
2016-02-01 01:08:45 276
原创 【Leetcode】LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if
2016-01-31 10:28:40 431
原创 【Leetcode】Binary Tree Level Order Traversal II
Very classic question and one of the hardest one I've met recently!!!The solution is also very clever and impressive! If I can solve this problem during interview, I guess Google could be my next in
2016-01-31 05:42:36 280
原创 【Leetcode】Two Sum II #Too easy, just review hashmap
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two number
2016-01-31 00:38:00 514
原创 【Leetcode】Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if the
2016-01-29 06:49:35 280
原创 【Leetcode】Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw
2016-01-29 05:51:56 305
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人