原创 LeetCode:328. 奇偶鏈表

一、問題描述 給定一個單鏈表,把所有的奇數節點和偶數節點分別排在一起。請注意,這裏的奇數節點和偶數節點指的是節點編號的奇偶性,而不是節點的值的奇偶性。 請嘗試使用原地算法完成。你的算法的空間複雜度應爲 O(1),時間複雜度應爲 O(nod

原创 LeetCode:21. Merge Two Sorted Lists

一、問題描述 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the

原创 LeetCode:148. Sort List

一、問題描述 Sort a linked list in O(n log n) time using constant space complexity. Example 1: Input: 4->2->1->3 Output: 1->

原创 LeetCode:160. Intersection of Two Linked Lists

一、問題描述 Write a program to find the node at which the intersection of two singly linked lists begins. For example, the f

原创 撲克牌中的順子

一、問題描述 從撲克牌中隨機抽 5 張牌,判斷是不是順子,即這 5 張牌是不是連續的。 2-10 爲數字本身,A 爲 1,J 爲 11,Q 爲 12,K 爲 13,而大小王可以看成任意的 數字。(大小王最多4張) 二、解題思路 1、首先我

原创 LeetCode:349. Intersection of Two Arrays

一、問題介紹 Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1], nums2 =

原创 把數組排成最小的數

一、問題介紹 輸入一個正整數數組,把數組裏所有數字拼接起來排成一個數,打印能拼接出的所有數字中最小的一個。例如輸入數組{3,32,321},則打印出這三個數字能排成的最小數字爲321323。 二、解題思路 定義新的大小關係,對vector

原创 調整數組順序使奇數位於偶數前面

一、問題描述 輸入一個整數數組,實現一個函數來調整該數組中數字的順序,使得所有的奇數位於數組的前半部分,所有的偶數位於數組的後半部分,並保證奇數和奇數,偶數和偶數之間的相對位置不變。 二、解題思路 兩個指針,一個首、一個尾。然後一個向前、

原创 STL:unordered_set 與set的區別

c++ std中set與unordered_set區別和map與unordered_map區別類似: 1.頭文件<unordered_set> <set> 2.. set基於紅黑樹實現,紅黑樹具有自動排序的功能,因此map內部所有的數據,

原创 LeetCode:287. Find the Duplicate Number

一、問題描述 Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at l

原创 LeetCode:3 Sum問題(C++實現)

一、問題描述 Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique t

原创 STL:set用法總結

一、Set介紹 除了沒有單獨的鍵,set 容器和 map 容器很相似。 定義 set 容器的模板如下四種: set<T> 容器保存 T 類型的對象,而且保存的對象是唯一的。其中保存的元素是有序的,默認用 less<T> 對象比較。可以用相

原创 LeetCode167. Two Sum II - Input array is sorted

一、問題描述 Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to

原创 STL:vector用法總結

一、簡介 vector是C++標準模板庫,是一個容器,底層是數組,爲連續內存,所屬頭文件爲<vector>。vector存儲數據時,會分配一個存儲空間,如果繼續存儲,該分配的空間已滿,就會分配一塊更大的內存,把原來的數據複製過來。 二、操

原创 Vim用法

vim --version 查看vim版本,如果沒有安裝,那就sudo apt-get install vim :q 退出 :q! 強制退出 在normal狀態下,按i(光標前)、I(光標後)、o(光標下一行)、O(光標上一行)、A(光標