原创 leetcode107&102&103

1、Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order traversal of its node

原创 leetcode349&350

1、Intersection of Two Arrays Given two arrays, write a function to compute their intersection. Example: Given num

原创 棧、隊列&leetcode225&155&232

c++中棧的簡單應用 定義 #include < stack > template < class T, class Container = deque< T > > class stack; stack< int >

原创 leetcode347

1、Top K Frequent Elements Given a non-empty array of integers, return the k most frequent elements. For example,

原创 leetcode459

1、 Repeated Substring Pattern Given a non-empty string check if it can be constructed by taking a substring of it

原创 leetcode409

1、Longest Palindrome Given a string which consists of lowercase or uppercase letters, find the length of the longe

原创 leetcode461

1、Hamming Distance The Hamming distance between two integers is the number of positions at which the corresponding

原创 排序算法總結

概述 排序有內部排序和外部排序,內部排序是數據記錄在內存中進行排序,而外部排序是因排序的數據很大,一次不能容納全部的排序記錄,在排序過程中需要訪問外存。 我們這裏說說八大排序就是內部排序。          當n較大,則

原创 由字符串匹配到KMP算法

字符串匹配問題就是在指對於兩段字符串,待匹配串和模式串,尋找待匹配串中模式串是否出現,及出現的位置。 例如在文本編輯中,我們經常要在一段文本中某個特定的位置找出某個特定的字符或模式。 1、簡單字符串匹配(BF-Brute Fo

原创 二分查找Binary Search

在一個有序的集合中查找元素,可以使用二分查找算法,也叫二分搜索。二分查找算法先比較位於集合中間位置的元素與鍵的大小,有三種情況(假設集合是從小到大排列的): 1、鍵小於中間位置的元素,則匹配元素必在左邊(如果有的話),於

原创 leetcode290

1、Word Pattern Given a pattern and a string str, find if str follows the same pattern. Here follow means a full ma

原创 leetcode392

1、 Is Subsequence Given a string s and a string t, check if s is subsequence of t. You may assume that there is on

原创 leetcode217

1、Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your function should r

原创 leetcode434&58

1、Number of Segments in a String Count the number of segments in a string, where a segment is defined to be a cont

原创 leetcode258

1、Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.