[LeetCode]743. Network Delay Time

原题There are N network nodes, labelled 1 to N.Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the target node, and w is the time it takes for a signal to travel from source to target.Now, we send a signal from a certain node K. How long will it take for all nodes to receive the signal? If it is impossible, return -1.NoteN will be in the ... Read More


一、预备知识—程序的内存分配一个由C/C++编译的程序占用的内存分为以下几个部分1、栈区(stack)—由编译器自动分配释放,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。2、堆区(heap)—一般由程序员分配释放,若程序员不释放,程序结束时可能由OS回收。注意它与数据结构中的堆是两回事,分配方式倒是类似于链表。3、全局区(静态区)(static)—全局变量和静态变量的存储是放在一块的,初始化的全局变量和静态变量在一块区域,未初始化的全局变量和未初始化的静态变量在相邻的另一块区域。程序结束后由系统释放。4、文字常量区—常量字符串就是放在这里的。程序结束后由系统释放。5、程序代码区—存放函数体的二进制代码。二、例子程序代码如下[code lang="cpp"//main.cpint a=0;  //全局初始化区char *p1;  //全局未初始化区main(intb;栈... Read More

LeetCode OJ Algorithm – Sliding Window Maximum(hard)

原题Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.For exampleGiven nums = [1,3,-1,-3,5,3,6,7], and k = 3.Window position Ma--------------- ----[1 3 -1] -3 5 3 6 7 1 [3 -1 -3]... Read More