原创 從求逆序對和mergeSort談起(2)

應用mergeSort的思想,可以解決許多和下標有關的問題。看了有關題的提示,發現有些能用Divide and Conqure解決的,也可以用 Binary Search Tree,Segment Tree,Binary Inde

原创 從求逆序對和mergeSort談起(3)

Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sor

原创 C語言printf()函數:格式

轉載於C語言中文網 printf()函數是最常用的格式化輸出函數,其原型爲: int printf( char * format, … ); printf()會根據參數 format 字符串來轉換並格式化數據,然後將結果

原创 307. Range Sum Query - Mutable.

Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. The update(i, va

原创 segment tree(線段樹)

簡介  線段樹(segment tree)是一種存儲區間的樹形結構,方便查詢哪一個區間包含了指定的點,原則上,它是一種固定結構, 一旦建成該樹,它的結構不會改變。 對於n個區間的集合,建一棵線段樹的時間複雜度和空

原创 97. Interleaving String

Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = “aabcc”,

原创 183. Customers Who Never Order

Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all c

原创 304. Range Sum Query 2D - Immutable

Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, co

原创 536. Construct Binary Tree from String

You need to construct a binary tree from a string consisting of parenthesis and integers. The whole input represent

原创 從求逆序對和mergeSort談起

先來談談mergeSort, 它是排序算法的一種,核心思想是:對一個數組nums[0,…,n],首先把它分成兩部分nums[0,…,mid]和nums[mid+1,…,n],首先兩個子數組是排好序的,只要對兩個子數組進行整合,然後

原创 循環鏈表的判斷

重新理解了快慢指針,判斷是否有循環這一問題。 142. Linked List Cycle II 287. Find the Duplicate Number 先看第一個:判斷循環鏈表 Given a linked lis

原创 221. Maximal Square

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.

原创 vector的內存管理

vector和string中有關容器大小管理的操作: c.capacity();//不重新分配內存空間的話,c可以保存多少元素 c.reserve(n);//分配至少能容納n個元素的內存空間 c.shrink_to_fit();//將ca