原创 Leetcode--Maximum Subarray

Maximum Subarray 原題:Find the contiguous subarray within an array (containing at least one number) which has the largest

原创 Leetcode: Largest Number

Given a list of non negative integers, arrange them such that they form the largest number. leetcode上的一道給定一個整形數組然後求其怎樣進

原创 宏定義(const)和常量定義(#define)的區別

宏定義(const)和常量定義(#define)的區別(轉載) 1.效果-《高質量C++/C編程指南》 C++ 語言可以用const 來定義常量,也可以用#define 來定義常量。但是前者比後者有更多的優點: (1) cons

原创 Leetcode--Find Peak Element

Find Peak Number: A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠

原创 Leetcode-- Sort Colors

Sort Colors 原題:Given an array with n objects colored red, white or blue, sort them so that objects of the same color ar

原创 自己動手寫字符串比較函數strcmp()

最近用到了字符串比較的函數,用到strcmp函數。除了知道怎麼用之外,我覺得有必要把它的源碼搞一搞。 搜到網上流傳的strcmp函數的源碼是如下: int strcmp (const char * src, const char * ds

原创 Leetcode-- Majority Elemeny

Majority Element 原題: Given an array of size n, find the majority element. The majority element is the element that a

原创 Search Insert Position Leetcode 非二分查找法

Search Insert Position--Leetcode 開始沒想到使用二分查找,就直接用的if else比較 low的做法,看運行時間還不算是最慢的,貼出來供以後查看。 class Solution { public:

原创 Leetcode--Reverse Bits

Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 000010100

原创 Kaggle-ValueError: Input contains NaN, infinity or a value too large for dtype('float32').

在按照教程一步一步做的時候,出現如下錯誤: ValueError: Input contains NaN, infinity or a value too large for dtype('float32'). 解決辦法: https

原创 斐波那契數列的各種算法實現

斐波那契數列,但凡學過編程的童鞋們應該都懂,背景就不介紹了(就是大兔子生小兔子的故事),無論是面試還是實際的運用,常見的一個思路就是先用最先基本的辦法實現,然後根據實際要求,一步步改進,優化算法效率。今天就以斐波那契數列這個大家都很熟悉的

原创 01揹包問題

01揹包問題是一個經典 的動態規劃的問題,現在再拿出來分享一下。 具體的,揹包問題一個例子來說就是:現在假設你有個揹包,容量是隻能裝下重量爲V=10kg的物品,現在桌子上有若干物品,但是不能把物品拆開拿走。假設現在有四種物品,wt={5,

原创 阿里筆試之最長公共子串

題目描述:給定一個query和一個text,均由小寫字母組成。要求在text中找出以同樣的順序連續出現在query中的最長連續字母序列的長度。例如,query爲“acbac”,text爲“acaccbabb”,那麼text中的“cba”爲

原创 不用加號實現加法!

有一個題目說的是如何不用加號來實現加法運算,看到了一個大牛的代碼,頓時膜拜!廢話不說,上思路。比如,int a =7, int b=8; 如何不用加號來計算a+b?代碼如下:<pre name="code" class="cpp">int

原创 數組中只出現一次的數字

數組中只出現一次的數字 題目:一個整形數組中除了兩個數字之外,其他的數字都出現了兩次。請寫程序找出只出現一次的數字。要求時間複雜度O(n),空間複雜度O(1)。 - 思路: 原來有個題目是所有的數字都是兩個,只有一個數字只出