原创 最後一個字的長度。

給定一個字符串,包含大小寫英文字母,計算最右一個字的長度。 空字符等返回0. C++版本。 class Solution { public: int lengthOfLastWord(const char *s) {

原创 旋轉整數

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Java代碼如下: public class So

原创 單獨數問題

Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm sh

原创 Max Points on a line ,在二維平面尋找共線的最多點

原題描述如下: Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 給定2維平面的N個

原创 二叉樹遍歷算法,前序

/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right;

原创 最深二叉樹 (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

原创 設計模式筆記之三(Iterator Pattern):

Iterator Pattern, 即迭代器模式,它讓使用者通過接口循環訪問容器中的元素,且不用瞭解底層的實體。 加入我們現在想訪問微信和Line的用戶,且打印出相關信息。 如大家所知,微信和Line屬於不同公司,因此對用戶列表的設計也

原创 HMM--隱馬爾科夫模型 (1)

想必大家都知道隱馬爾科夫模型的重要性吧。 本文簡單介紹我對HMM的理解,有什麼問題相互學習,共同進步。賊哈哈~~~ 一個簡單的例子: 假設每天的天氣要麼晴天,要麼下雨。(有人會說太扯淡了,還有陰天什麼,多雲什麼的。)不過前面說了簡單的例子

原创 井岡山和梁山的異同

成王敗寇!

原创 Leetcode, 組合序列生成

給定一個n和k,給出c_{n}^k的所有組合。 例:給定n=4,k=2,輸出, [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] 一下是C++實現。 class Sol

原创 LeetCode 從鏈表中刪除倒數第N個節點

從單鏈表中刪除倒數第N個節點,要求之遍歷一遍鏈表。 例子如下: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from

原创 旋轉列表

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->NU

原创 判斷鏈表是否循環,找出循環點

判斷鏈表是否循環,找出循環點。 例子: 輸入, A->B->C->D->E->C 輸出: C class Node { char data; Node next; Node(char d, Node n) { data = d

原创 Leetcode 平衡樹判別

判斷一顆二叉樹是否平衡。 /** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; *

原创 Binary Tree Level Order Traversal, 二叉樹層級遍歷

[LeetCode]  Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to r