原创 LeetCode·15. 3Sum

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

原创 C++·內存泄露以及常見的解決方法

1.什麼是內存泄漏(memory leak)? 指由於疏忽或錯誤造成程序未能釋放已經不再使用的內存的情況。內存泄漏並非指內存在物理上的消失,而是應用程序分配某段內存後,由於設計錯誤,失去了對該段內存的控制,因而造成了內存的浪費。

原创 HTTP·校招面試題

1. 一次完整的HTTP請求所經歷的7個步驟 HTTP通信機制是在一次完整的HTTP通信過程中,Web瀏覽器與Web服務器之間將完成下列7個步驟: 1. 建立TCP連接 在HTTP工作開始之前,Web瀏覽器首先要通過網絡與We

原创 LeetCode·39. Combination Sum

題目: 39. Combination Sum Given a set of candidate numbers (candidates) (without duplicates) and a target number (ta

原创 LeetCode·114. Flatten Binary Tree to Linked List

思路:先序遍歷 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; *

原创 LeetCode·33. Search in Rotated Sorted Array

題目: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,

原创 C++·計算結構體大小

結構體中可以定義的數據類型: 1. 基本類型 2. 上面已經出現過的數據類型,比如說上面已經定義過的結構體 3. 指向自己的指針 由於內存對齊的問題,各個數據類型放的位置不同就會導致結構體的大小不一樣。 偏移量:結構體中的偏

原创 C++·線程與進程

一、多線程的好處 1.發揮多核CPU的優勢 隨着工業的進步,現在的筆記本、臺式機乃至商用的應用服務器至少也都是雙核的,4核、8核甚至16核的也都不少見,如果是單線程的程序,那麼在雙核CPU上就浪費了50%,在4核CPU上就浪費了7

原创 LeedCode·16. 3Sum Closest

題目: Given an array nums of n integers and an integer target, find three integers in nums such that the sum is close

原创 Effective C++ 閱讀筆記·Miscellany

53 Pay attention to compiler warning 嚴肅對待編譯器發出的警告信息; 不要過度依賴編譯器的報警能力,因爲不同的編譯器對待事情的態度並不相同。一旦移植到另一個編譯器上,你原本依賴的警告信息有可能

原创 Effective C++ 閱讀筆記·Customizing new and delete

operator new 和 operator delete只適合用來分配單一對象。Array所用的內存由operator new[] 分配出來,並由operator delete[] 歸還。STL容器所使用的heap內存是由容

原创 LeetCode·18. 4Sum

題目: Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a

原创 C++·STL相關

各種容器的元素在內存中的儲存方式 1、vector(向量):相當於數組,但其大小可以不預先指定,並且自動擴展。它可以像數組一樣被操作,由於它的特性我們完全可以將vector 看作動態數組。在創建一個vector 後,它會自動在內存

原创 LeetCode·31. Next Permutation

題目: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of num

原创 HTTPS工作原理及優缺點

HTTPS其實是有兩部分組成:HTTP + SSL / TLS,也就是在HTTP上又加了一層處理加密信息的模塊。服務端和客戶端的信息傳輸都會通過TLS進行加密,所以傳輸的數據都是加密後的數據 一、HTTP工作原理: