自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Pushing Code

来把这个码Gank了

  • 博客(107)
  • 资源 (2)
  • 收藏
  • 关注

转载 longest increasing continuous subsequence in a 2D matrix

dp + dfs //These two are only for traversing around x,y public int[] xMove = { 1, 0, 0, -1 }; public int[] yMove = { 0, 1, -1, 0 }; public int longestIncreasingContinuousSubsequenceII(int

2015-09-17 02:16:48 427

转载 perfect squares find the least number of perfect square numbers (1, 4, 9, 16, ...) which sum to n

用动态规划Dynamic Programming来做,我们建立一个长度为n+1的一维dp数组,将第一个值初始化为0,其余值都初始化为INT_MAX, i从0循环到n,j从1循环到i+j*j <= n的位置,然后每次更新dp[i+j*j]的值,动态更新dp数组,其中dp[i]表示正整数i能少能由多个完全平方数组成,那么我们求n,就是返回dp[n]即可,也就是dp数组的最后一个数字,参见代码如下:int

2015-09-17 02:01:21 538

转载 missing ranges of sorted integer array

大自然的搬运工:http://www.danielbit.com/blog/puzzle/leetcode/leetcode-missing-ranges Given a sorted integer array where the range of elements are [0, 99] inclusive, return its missing ranges. For example, g

2015-09-17 00:53:29 317

转载 find maximized count of 0 on left and 1 on right in binary array

给定一个 array,只包含 0,1, 找到一个分割位置,使左侧 0 出现的个数和右侧 1 出现的个数之和最 大化brute force, time: O(n^2), space: O(1) follow up, can we solve in O(n): DP, two temp array-google 1point3acres follow up, can we use O(1) spac

2015-09-17 00:48:19 312

转载 serialize a list of string and deserialize it

import java.util.*;public class combineStrings{ public static void main(String[] args) { String[] arr = {"abc%cde", "a#aa", "haha"}; for(String s : arr) {

2015-09-17 00:46:41 319

转载 wiggle sort Given a list of integers, sort them so the output is s1 <= s2 >=s3 <=s4 ... sN.

每个元素和后一个元素比较看是不是希望的次序,如果不是的话互换就好public void wiggle_sort(int[] arr) { int n = arr.length; if(n <= 1) return; boolean inc = true; int prev = arr[0]; for(int i=1; i<n; i++) {

2015-09-17 00:18:54 466

转载 Reservoir Sampling (a random element from indefinite length stream with same probability)

Reservoir Sampling Reservoir sampling is a family of randomized algorithms for randomly choosing k samples from a list of n items, where n is either a very large or unknown number. Typically n is larg

2015-09-17 00:07:01 541

转载 calculate sorted y of function y = ax^2 + bx + c given sorted x array

给定一个一元二次方程式y = ax^2 + bx + c, 一个sorted array X, 将X中所有元素代入方程中,返回sorted的Ysolution: 看a< or > 0,,搞出两边的y们,然后mergepublic class Ax2 { public static void main(String[] args) { } // x is sorted array

2015-09-16 15:42:31 584

转载 Randow Id generator with array of probability

给一组id和表示每个id出现概率的数组,概率之和为1.要求随机生成id,使得随机出的id满足之前的概率数组。**如果id很多,调用这个随机生成方法的次数也很多,怎么优化使用prefix sum,使用binary searchclass RandomID { public static void main(String[] args) { int[] id = { 1, 2,

2015-09-16 15:29:42 476

转载 different/Unique/distinct Binary Search Trees

Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ /

2015-09-16 15:24:05 632

转载 adding up two (sum) big/large number with string representation

public static String sumStrings(String a, String b) { char[] num1 = a.toCharArray(); char[] num2 = b.toCharArray(); int i = num1.length - 1; int j = num2.length - 1;

2015-09-16 11:30:41 271

转载 Find a sorted subsequence of size 3 three in linear time

Given an array of n integers, find the 3 elements such that a[i] < a[j] < a[k] and i < j < k in 0(n) time. If there are multiple such triplets, then print any one of them.Examples:Input: arr[] = {12,

2015-09-16 10:53:29 342

转载 Data Structure for HTML DOM with compare text inside

1. 设计HTML DOM数据结构信息是<html><body><p>Hello</p></body></html>或者<html><body><p><b>H</b>ello</p></body></html>【提示是类似tree】2. 写一个方法比较两个HTML数据中存粹文本是否一样. 鍥磋鎴戜滑@1point 3 acres上面两个例子都是Hello,所以此方法返回truepub

2015-09-16 10:20:35 313

转载 compute exact number of triples of distinct elements in large array

Given an array of N=10^6 int32 and an int32 X, compute the exact number of triples (a, b, c) of distinct elements of the array so that a + b + c <= X public int threeSumSmaller(int[] nums, int targe

2015-09-16 10:10:30 445

转载 fast Update, sum operation of 2D matrix

Given a 2D space of maximum size NxN which supports two operations : [1] void UPDATE(x,y,v) - sets the value of cell [x,y] to v [2] int SUM(x1,y1,x2,y2) - returns sub-rectangle sum (x1,y1) to (x2

2015-09-16 09:45:27 375

转载 Find the longest substring with k unique distinct characters in a given string (Google)

The problem can be solved in O(n). Idea is to maintain a window and add elements to the window till it contains less or equal k, update our result if required while doing so. If unique elements exceeds

2015-09-16 09:03:14 351

原创 distinct sequence Google

leetcode ,暴力解法dfs, 双指针,不行 public int numDistinct(String s, String t) { return numDistinctHelper(s,t,0,0); } public int numDistinctHelper(String s, String t, int si, int ti){

2015-09-16 08:35:14 337

转载 Rearrange int array to put odd number to left and even to right

双指针,左右调换。no extra memory, O(n)class Solution: def sepOddEven(self, nums): if not nums or len(nums) == 0: return None left = 0 right = len(nums) - 1 while left < righ

2015-09-16 03:30:07 352

转载 float number square root

public float sqrt(float f, int p), precision是表示小数点后位数(2就要两位一致) p is the number of digits after the decimal point has to be rightSolution: 判断数据是否符合精确度,就用两个数都乘以10^p,再取整比较是否相等。比如p=2, f=0.64, curRes =

2015-09-16 02:10:13 536

原创 word abbreviation

一个string只保留首尾字母, 中间字母数用数字表示, 比如 “abcde” = “a3e”, “ab” = “ab”, “abc” = “a1c” . 给一组string, 输出相同abbreviation的所有string, 但重复的string不算.abv_string = StringBuilder.append(charAt[0]), StringBuilder.append(str.

2015-09-15 23:41:41 407

原创 Longest Consecutive Sequence

思路:既然要O(n)算法,排序显然不行,所以自然想到用hash table。将序列中的所有数存到一个unordered_set中。对于序列里任意一个数A[i],我们可以通过set马上能知道A[i]+1和A[i]-1是否也在序列中。如果在,继续找A[i]+2和A[i]-2,以此类推,直到将整个连续序列找到。为了避免在扫描到A[i]-1时再次重复搜索该序列,在从每次搜索的同时将搜索到的数从set中删除。

2015-09-15 12:59:45 227

转载 Rearrange a string so that all same characters become d distance away minDistance priority queue

Given a string and a positive integer d. Some characters may be repeated in the given string. Rearrange characters of the given string such that the same characters become d distance away from each oth

2015-09-15 12:10:42 653

转载 find duplicates in matrix within k indices

import java.util.*;public class find_dupicates_within_k_indices { static class Pos { int row; int col; Pos(int row, int col) { this.row = row; this.

2015-09-14 09:39:59 423

转载 rotate matrix m*n

rotate a m*n matrix, not in place:void rotate(int row int col, int arr[][row],int rot_arr[][col]){ for(int j = 1; j < row; j++) { for (int i = m-1 , k = 0; i >= 0, k < m; i--, k++)

2015-09-14 09:31:39 267

转载 find path/route in a maze 2 d matrix

http://www.geeksforgeeks.org/backttracking-set-2-rat-in-a-maze/#include<stdio.h>#include <stdbool.h>// Maze size#define N 4 void printSolution(int sol[N][N]){ int i, j; for (i = 0; i < N; i+

2015-09-01 12:17:37 317

转载 Greatest common divider

static int gcd(int a, int b){ if(a == 0 || b == 0) return a+b; // base case return gcd(b,a%b);}

2015-09-01 11:54:39 303

转载 Amazon online assessment OA two sum (check how many 多少对)

看有多少对,而不是有没有public class Solution { public int[] twoSum(int[] nums, int target) { int count = 0; if(nums == null || nums.length == 0) { return count; }

2015-08-27 12:01:41 2212

转载 string rotation (if string is the rotate of the other)

ex: ABCD -> CDAB or DABCIf str1 is the substring of str2 concatenated with itself(str2), then it is the rotation of itboolean isRotation(String s1,String s2) { return (s1.length() == s

2015-08-27 02:05:44 452

转载 [Amazon]Given 2 numbers. Find if they are consecutive gray (grey) code sequences

http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=105773&extra=page%3D1%26filter%3Dsortid%26sortid%3D311%26sortid%3D311//term1和term2是题目给的两个BYTEbyte x = (byte)(term1 ^ term2);int total = 0;

2015-08-21 03:33:07 994

转载 [Amazon ]去元音 get rid of vowels

去元音: http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=105773&extra=page%3D1%26filter%3Dsortid%26sortid%3D311%26sortid%3D311//string 是题目给的字符串StringBuffer sb = new StringBuffer();String v

2015-08-21 03:24:01 1077

转载 [Amazon] Find loop in a singly linkedlist

As the title sayshttp://stackoverflow.com/questions/2663115/how-to-detect-a-loop-in-a-linked-list Floyd’s cycle-finding algorithm Having a fast and slow pointerboolean hasLoop(Node first) { if(f

2015-08-21 02:21:06 458

原创 [LeetCode]Word Break

https://leetcode.com/problems/word-break/Got the solution from here http://blog.csdn.net/linhuanmars/article/details/22358863. Quite clever. Interestingly it kind of use the similar approach from a que

2015-04-09 11:15:28 424

原创 Find longest covered length of non overlapping interval subsets

Given a list of intervals, find a subset of it that covers the longest length and doesn’t overlap with each otherSolution credit to my brother, Jiasen Linimport java.util.ArrayList;import java.util.Co

2015-04-09 09:55:18 714

原创 Java regular expression regex

http://www.tutorialspoint.com/java/java_regular_expressions.htm

2015-04-08 05:35:02 353

原创 Lowest/first common ancestor

public interface FirstCommonAncestor { /** * Given two nodes of a tree, * method should return the deepest common ancestor of those nodes. * * A * / \ * B C * / \ \ * D E M * / \

2015-04-08 01:06:08 540

原创 can I win(judge first player to move can win)

/* In "the 100 game," two players take turns adding, to a running total, any integer from 1..10. The player who first causes the running total to reach or exceed 100 wins. What if w

2015-04-08 00:40:06 1180

原创 reverse a linked list

//in place and in one passListNode *reverse(ListNode *head) { if (!head) return head; ListNode dummy(0); dummy.next = head; ListNode *p = &dummy; while(head->next) { ListNode

2015-04-08 00:37:34 328

原创 [LeetCode]longest common/same prefix

//比较每个位置的字母 string longestCommonPrefix(vector<string> &strs) { string prefix; if(strs.size() ==0) return prefix; int len =0; while(1)

2015-04-07 23:29:54 446

原创 Flowerbed can place flowers problem

/* Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both

2015-04-07 14:41:56 1659

原创 Find the first intersection of two lists (if the two list are merged at some point)

http://www.geeksforgeeks.org/write-a-function-to-get-the-intersection-point-of-two-linked-lists/ Method 3(Using difference of node counts) 1) Get count of the nodes in first list, let count be c1. 2

2015-04-07 14:20:08 421

Computers as Components(购买版电子书. 清晰非扫描)

《嵌入式计算系统设计原理》的英文原版,这是购买版的电子书,价值$10.99,非扫描,特发上来给大家分享

2012-08-02

head first java (购买版电子书,价值$44.95. 清晰非扫描)

此书为head first java的原版电子书(英文版),亚马逊官网购买该电子书价值$44.95。 特发出来给大家参考学习。 绝对清晰,文中的字都是可以复制的。非扫描

2012-08-02

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除