原创 Intersection of Two Arrays【合併兩個set】

PROBLEM:Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2

原创 Degree of an Array【一個數組的度】

PROBLEM:Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequ

原创 Java與C++對比學習

c++ string類的substr()方法中的第二個參數爲長度; Java String類的substring()方法中的第二個參數爲不包括的結束位置; python中的字符串由 [start : end] 獲得,兩個參數含義和java

原创 3Sum【三個數和爲0】

PROBLEM: Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique

原创 10 分鐘瞭解 Actor 模型

過去十幾年CPU一直遵循着摩爾定律發展,單核頻率越來越快,但是最近這幾年,摩爾定律已然失效,CPU的工藝製程和發熱穩定性之間難以取捨,取而代之的策略則是增加核心數量,目前家用電腦四核已經非常常見,服務器更是達到了32核64線程。爲了有效地

原创 進程和線程的區別

在理解進程和線程概念之前首選要對併發有一定的感性認識,如果服務器同一時間內只能服務於一個客戶端,其他客戶端都再那裏傻等的話,可見其性能的低下估計會被客戶罵出翔來,因此併發編程應運而生,併發是網絡編程中必須考慮的問題。實現併發的方式有多種:

原创 Repeated Substring Pattern【重複的子字符串【KMP】】

PROBLEM:Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copi

原创 Nth Digit【第n個數字】

PROBLEM:Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...Note:n is positive an

原创 Number Complement【求反碼】

PROBLEM:Given a positive integer, output its complement number. The complement strategy is to flip the bits of its bina

原创 Find Mode in Binary Search Tree【找到BST樹中出現最多的元素】

PROBLEM: Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element)

原创 【 C/C++ & Python】隨機數產生

C++中有兩種方式:第一種方式是使用<cstdlib>中的rand()函數,這是ANSI C標準,在gcc/g++編譯器中也直接可用;第二種方式是使用<random>庫文件,下面對這兩種方法進行介紹:1、<cstdlib> & rand(

原创 關於約瑟夫環問題的理解

有序列:0,1,2,3......,n-1(可以將0~n-1的序列值理解爲任意數組下標),每次刪除第m個,注意該序列首尾相連,即n-1的下一個爲0,問最後剩下的數字是多少? 此問題被稱爲約瑟夫環問題,可以用枚舉找規律解決,但也可以使用動態

原创 Palindrome Number【判斷一個數是不是迴文】

PROBLEM:Determine whether an integer is a palindrome. Do this without extra space.SOLVE(C++):class Solution { public:

原创 【C++】string對象的大小寫轉換

C++中string對象可以使用 algorithm 頭文件中的 transform 函數和進行大小寫轉換。string tmp = "Test"; string tmpLower; transform(tmp.begin(), tmp.

原创 【Python】瑣碎知識點整理記錄

1、sorted( )[i:j:-1] 排序完了直接逆序切片,且 i,j 範圍爲-1>=i>j,切片範圍爲i~j-1;2、map(function, list) 將第一個方法作用於後一個數組上的所有元素,注意python3中map函數直接