原创 劍指Offer面試題55:字符流中第一個不重複的字符 Java實現

題目:字符流中第一個不重複的字符         請實現一個函數用來找出字符流中第一個只出現一次的字符。例如,當從字符流中讀出前兩個字符“go”時,第一個只出現一次的字符是“g”.當從該字符流中讀出前六個字符“google”時,第一個只

原创 劍指Offer面試題56:鏈表中環的入口節點 Java實現

題目:鏈表中環的入口節點         一個鏈表中包含環,如何找出環的入口節點?例如,下圖中的入口節點是3.              1->2->3->4->5->6                          ^   

原创 劍指Offer面試題58:二叉樹的下一個節點

題目:二叉樹的下一個節點           給定一顆二叉樹和其中的一個節點,如何找出中序遍歷的下一個節點?樹中的節點除了有兩個分別指向左右子節點的指針以外,還有一個指向父節點的指針。 算法分析: 整個算法中需要考慮的二叉樹情況分爲

原创 劍指Offer面試題53:正則表達式匹配 Java實現

題目:正則表達式匹配     請實現一個函數用來匹配包含‘.’和‘*’的正則表達式。模式中的字符’.’表示任意一個字符,而‘*’表示它前面的字符可以出現任意次(含0次)。本題中,匹配是指字符串的所有字符匹配整個模式。例如,字符串“aaa

原创 劍指Offer面試題5:從尾到頭打印鏈表

題目:從尾到頭打印鏈表 輸入一個鏈表的頭節點,從尾到頭反過來打印輸出每個節點的值。 算法分析:         看到這道題,很多人的第一反應是從頭到尾輸出將會比較簡單,於是我們很自然的想到把鏈表中的節點的指針反轉過來,改變鏈表的方向

原创 Comparatable接口和Comparator接口的使用與區別

以下文章轉自該博客:  http://blog.sina.com.cn/s/blog_63c66eb60100slyc.html 這篇博文可以爲你解決的問題如下: 什麼是自然排序 Collections.sort()與Arrays.

原创 LeetCode013:Roman to Integer

原題目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 將羅馬

原创 LeetCode10:Regular Expression Matching

原題目: Implement regular expression matching with support for '.' and '*'.   '.' Matches any single character. '*' Ma

原创 LeetCode11: Container With Most Water

原題目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical li

原创 LeetCode014:Longest Common Prefix

原題目: Write a function to find the longest common prefix string amongst an array of strings. 找到一個字符串數組中,最長的公共前綴子串,並

原创 LeetCode12:Integer to Roman

原題目: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 給定一個

原创 寬度優先搜索

寬度優先搜索又譯爲廣度優先搜索算法(英語:Breadth-First-Search,縮寫爲BFS),或橫向優先搜索,是一種圖形搜索算法。簡單的說,BFS是從根節點開始,沿着樹的寬度遍歷樹的節點。如果所有節點均被訪問,則算法中止。它的思想是

原创 LeetCode05:Longest Palindromic Substring

原題目: Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1

原创 LeetCode04:Median of Two Sorted Arrays

原題目: There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The

原创 LeetCode09:Palindrome Number

原題目: Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: C