Friday, September 20, 2013

[LeetCode] Anagrams Rotate List

Given a list, rotate the list to the right by k places, where k is non-negative.

For example:
Given 1->2->3->4->5->NULL and k = 2,
return 4->5->1->2->3->NULL.

Idea:

  • link the tail to head to construct a circle
  • start from head until stop by total - (k%total)
  • set tail.next to null to break the circle




Thursday, September 19, 2013

[LeetCode] Anagrams

Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.

Idea: 

  • Put the array of String(convert to char) into a queue
  • Merge sort all of the item in the queue
  • Use a Hashtable, put sorted string as key, Stack as value (which has a stack of original string)
  • Iterate the Hashtable, Iterate stack which size is greater than, put the String into ArrayList from that stack

Wednesday, September 18, 2013

可爱的猫猫们





[LeetCode]Two Sum

Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.
You may assume that each input would have exactly one solution.
Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2

Idea: use hashtable to effectively search item, search complexity is o(1) and use linkedlist to avoid collision



杂记--身体抱恙


清晨,迷迷糊糊地从梦中起来,感觉身体已无大碍,昨夜发烧的额头已没有了滚烫的感觉,身体感觉有些乏力,但是已然没有了昨晚全身酸痛发烧的感觉。多亏臭臭的细心照顾,又熬姜汤又搓胳膊的,才能这样快的康复。想想生病的原因,也许是前段时间事业受阻,亦或是工作的地方空调开得过于凶猛,也就稀里糊涂的病了。

九月末佛州的早上,空气中夹杂着一股凉意,不冷不热的,让我想起家里的感觉。那时候,这么早起来还属于学生的时代,每天要坐一段公交车。而从家里走到车站的五分钟里,就能感受到这股凉意,沁人心脾。

这段时间有些迷惘,有些失落,不知今后回头看自己的现在,是何种滋味。。

还好有臭臭陪着,加油,我们一起~


Tuesday, September 17, 2013

Embed Code with Blogger Tutorial


SyntaxHighlighter is a fully functional self-contained code syntax highlighter developed in JavaScript.

You can find more detail about SyntaxHighlighter at http://alexgorbatchev.com/SyntaxHighlighter/

SyntaxHighlighter provides a broad syntax library for users to highlight their code.


Here is a screen shot on how many language does current version support:




The idea is pretty straightforward, you just need to link the .js file in your blog, and then simply tell the blog about which part you want to show as Code. Want to know how to do it? I will walk you through on how to create a blog template, create embedded code page and apply for different theme.


Now, let's start:


First, We need to select the Edit HTML.



Under Edit HTML,  find the tag </head>, you need to put SyntaxHighlighter brush library here.

Copy and pasta following code:


    
    


After Saving the the template, you have done the first step!


Then, you can create your new post as usual.  


Next, switch your view from compose to HTML view



Put the code you want, for simplicity, I will do the following code:



/**
     * SyntaxHighlighter
     */
    function foo()
    {
        if (counter <= 10)
            return;
        // it works!
    }

It will show like


/**
     * SyntaxHighlighter
     */
    function foo()
    {
        if (counter <= 10)
            return;
        // it works!
    }

Now you have done pretty much of all of them!

Finally, you may not like the theme of your code. You can find all the theme here.
All you need to do is go back to the first step, edit HTML, Find one line of code like:

Change to the theme you would like to use, for example:


Now you can create the embedded code HTML yourself, enjoy!

I hope this blog will be helpful!