原创 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 play

原创 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 siz

原创 [LeetCode]longest common/same prefix

//比較每個位置的字母 string longestCommonPrefix(vector<string> &strs) { string prefix; i

原创 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

原创 string rotation (if string is the rotate of the other)

ex: ABCD -> CDAB or DABC If str1 is the substring of str2 concatenated with itself(str2), then it is the rotation of

原创 Lowest/first common ancestor

public interface FirstCommonAncestor { /** * Given two nodes of a tree, * method should return the deepest comm

原创 [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

原创 wiggle sort Given a list of integers, sort them so the output is s1 =s3

每個元素和後一個元素比較看是不是希望的次序,如果不是的話互換就好 public void wiggle_sort(int[] arr) { int n = arr.length; if(n <= 1) re

原创 [Amazon] Find loop in a singly linkedlist

As the title says http://stackoverflow.com/questions/2663115/how-to-detect-a-loop-in-a-linked-list Floyd’s cycle-

原创 [Amazon ]去元音 get rid of vowels

去元音: http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=105773&extra=page%3D1%26filter%3Dsortid%26sortid

原创 Java regular expression regex

http://www.tutorialspoint.com/java/java_regular_expressions.htm 點贊 收藏 分享 文章舉報 Seth_Li

原创 Amazon online assessment OA two sum (check how many 多少對)

看有多少對,而不是有沒有 public class Solution { public int[] twoSum(int[] nums, int target) { int count = 0;

原创 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

原创 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 other S

原创 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 di