【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
【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
【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
【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
学了一招合并几万个文件 之前都知道合并,单纯的 cat * > merged_file 就可以了,但是今天要出了几万个文件就会报错,所以我研究了一下怎么办。第一个人说可以利用xargs,但是失败了。。。我也不知道为什么,知道的朋友告诉我一下,我看着还挺有道理的:ls | xargs -n 32 -P 8 cat >> ../saved_output第二个这个work了,非常精彩: ls | whi
【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
【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
【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
【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
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.
【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
【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.————————————————————————最近准备开始
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
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
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
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
LFU Cache 与LRU不同LFU关注与出现的频率,然后想自己写一个,区别在于:如果是LRU,假如capacity是2:输入是ABCBBBBBBCAA,那么最后会剩下的是C和A在缓存里。但是如果是LFU,capacity也是2:输入是ABCBBBBBBCAA,最后剩下的是[A,B],因为B出现的频率高。也就是说就算之前因为频率低被淘汰了,后面又出现了也要再回来。所以我想的设计方案是,整个LFUCach
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,
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.
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 {