自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

这个世界,它还是它。

只是,你的想法在变。

  • 博客(96)
  • 问答 (1)
  • 收藏
  • 关注

原创 109. Convert Sorted List to Binary Search Tree

Qhttps://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/?tab=Description Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.A

2017-02-09 12:55:40 658

原创 106. Construct Binary Tree from Inorder and Postorder Traversal

Qhttps://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/Given inorder and postorder traversal of a tree, construct the binary tree.A/** * Definition for a binary tree

2017-02-09 11:24:10 359

原创 105. Construct Binary Tree from Preorder and Inorder Traversal

Qhttps://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/Given preorder and inorder traversal of a tree, construct the binary tree.A”’c /** * Definition for a binary

2017-02-09 11:23:09 427

原创 108. Convert Sorted Array to Binary Search Tree

Qhttps://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/Given an array where elements are sorted in ascending order, convert it to a height balanced BST.A/** * Definition for a binar

2017-02-09 11:21:34 320

原创 96. Unique Binary Search Trees

QGiven n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example, Given n = 3, there are a total of 5 unique BST’s.SCatalan数 参考:http://www.cnblogs.com/NickyYe/p/42

2017-01-23 07:50:43 231

原创 98. Validate Binary Search Tree

QGiven a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node’s key. The righ

2017-01-13 14:54:57 359

原创 113. Path Sum II

TGiven a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.S/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *l

2017-01-06 16:12:10 226

原创 112. Path Sum

TGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.S/** * Definition for a binary tree node. * struct

2017-01-06 15:43:45 266

原创 111. Minimum Depth of Binary Tree

TGiven a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.S/** * Definition for a binary tree node.

2017-01-06 15:17:04 288

原创 110. Balanced Binary Tree

TGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by

2017-01-06 14:33:41 226

原创 104. Maximum Depth of Binary Tree

TGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.S/** * Definition for a binary tree node.

2017-01-05 14:29:35 313

原创 101. Symmetric Tree

QGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric:But the following [1,2,2,null,3,null,3] is not:

2017-01-04 14:47:48 252

原创 cat

#include <stdio.h>#include <stdlib.h>void filecopy(FILE *ifp, FILE *ofp) { int c; while ((c = getc(ifp)) != EOF) { // #define EOF -1 putc(c, ofp); }}int main(int argc, char *argv[]

2016-12-12 14:52:42 403

原创 C语言操作符顺序

C operators sequence

2016-11-18 15:47:49 463

原创 声明的意义

当定义了一个变量时,它是什么意思呢,这里是一个简单的一次性解释声明的小程序,之后再改一下,可以一次运行,重复输入就OK了。// 无法重复循环该程序#include <stdio.h>#include <ctype.h> // isalnum()#include <string.h> // strcpy()#include <stdlib.h> // atoi()#define MAXTOK

2016-11-15 10:22:20 580

原创 指针与动态数组

C语言中如何实现动态数组:使用malloc()库函数(内存分配)来得到一个指向一大块内存的指针;像引用数组一样引用这块内存如果需要使数组有动态增长的能力,那就修改内存的总容量,直接在运行时在堆上分配数组的内存。这就用到库函数realloc(),它能够对一个现在的内存块大小进行重新分配(通常是实质扩大),同时不会丢失原先内存块的内容。#include <arpa/inet.h>#include

2016-11-15 10:16:19 1688

原创 strlen函数

寻找一种更好的算法比改良一种差劲的算法更有效率。#include <stddef.h> // size_t#define MAXLEN 100#include <stdio.h>size_t strlen (char const *string) { int length; for (length = 0; *string++ != '\0'; ) { // *string++,

2016-11-15 10:08:44 382

原创 Some Questions of Process API(2)

4. Write a program that calls fork() and then calls some form of exec() to run the program /bin/ls. See if you can try all of the variants of exec(), including execl(), execle(), execlp(), execv(), exe

2016-10-23 10:03:16 447

原创 虚拟内存分配和管理接口(VM allocation interfaces)

关于虚拟内存的分配和管理(Virtual Memory, VM)大概了解一下Unix系统中内存分配接口(memory allocation interfaces in Unix systems),这里先只是:介绍2种内存管理的库调用详细介绍堆上内存手动分配和释放函数(malloc/free)问题的关键在于:怎样分配和管理内存1. 内存种类(Types of Memory) In runni

2016-10-21 17:19:15 939

原创 The Abstraction: Address Spaces(地址空间)

一个打印虚拟存储器地址分配的小程序:main()函数的地址存在heap上的地址存在stack上的地址#include <stdio.h>#include <stdlib.h>int main(int argc, char *argv[]) { printf("location of code : %p\n", (void *) main); printf("location

2016-10-17 23:38:53 439

原创 无向图1(UNDIRECTED GRAPHS)

图和图像的无关性A drawing gives us intuition about the structure of the graph; but this intuition can be misleading, because the graph is defined independently of the drawing.For example, the two drawings at l

2016-10-14 16:16:49 1434

原创 平衡查找树——2-3查找树——红黑树(1)

二叉查找树VS平衡查找树Binary Search Tree possibilitiesBalanced Search Trees如何学 平衡查找树为了保证之前学习的二分查找树BST的平衡性,解决在最坏情况时高度为N的情况,这里有几种平衡查找树:AVL2-3 Search TreesRed-black BSTs ——红黑二叉查找树直接关注最重要的一种搜索树——红黑树,在SGI STL中红黑树

2016-09-30 14:41:30 3405

原创 二叉查找树BST(2)

经典算法书关于算法的一些推荐书籍,可以看下这里BST API#include <iostream>using std::cout;using std::cin;using std::endl;using ElemType = int;class BST {private: struct Node { ElemType data; Node *left;

2016-09-29 15:13:44 452

原创 推荐两本算法书

完善一下BST,后续还会继续完善,然后将一些讲解贴出来。#include <iostream>using std::cout;using std::cin;using std::endl;using ElemType = int;class BST {private: struct Node { ElemType data; Node *left;

2016-09-28 23:00:15 5451

原创 union-find(并查集)

推荐一本普林斯顿大学实战型数据结构与算法书全书用java实现,之前没用过java不用担心的。真是感觉曾经的自己那么naive(当然现在依旧,只不过naive level降低了…),当年为什么就是不明白并查集,觉着非常高端。记着那几个学长讲到这里时,就是彻底不懂。现在,起码给你思想,你能懂了。声明:切的图片、敲的代码都来自本书union-find API(1)UF(int N) // initiali

2016-09-28 11:30:43 306

原创 Operating Systems

Three levelvirtualizationconcurrencypersistenceWhy need OS virtualize resources?This is not the main question, as the answer should be obvious: it makes the system easier to use.How to virtualize r

2016-09-27 15:27:06 688

原创 Some Questions of Process API(1)

Some Questions of Process APIRecord some code of calling Process API to enhance the understanding of these API. Some questions and related coding. It’s even more fun than it sounds!Aside(RTFM – READ

2016-09-25 12:10:35 1134

原创 关于读书梯度的领会

单从计算机类书籍方面说读书一定要读经典书,比如学习C语言,可以看下C之父的书(是的,就是那本);学C++可以读一下《C++ primer》;学习OS,读…exception 1但是,有写经典书,不是你想读就能读的,得看你的水平。比如说,当你刚要学C++,可能,我说的可能,你要去看《C++ primer》就可能看不懂,那怎么办?先去此类书籍中简单点儿的书,当然尽量还是经典书。exception 2还有

2016-09-22 10:46:48 270

原创 C语言模拟shell命令1

Process API在UNIX系统中,如何创建进程?UNIX在提供的system calls中,有一对非常奇异的创建新的进程system calls: fork()exec()当然,要用这两个system calls,还要用到wait(),通常是一个进程用来等待另一个进程完成。关于为什么UNIX给了这么几个奇异的接口来创建一个新的进程呢?历史证明吧!在构建UNIX shell中,fork()

2016-09-22 09:45:19 1545

原创 72. Edit Distance

ProblemGiven two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a wor

2016-09-16 18:12:05 209

原创 70. Climbing Stairs

ProblemYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Solution题目思路了很简单了:dp[i] = dp[i

2016-09-16 16:09:29 171

原创 二分查找

将通常见到的两种二分查找的方式纪录在这里。关于第二种方式,会涉及到类似STL库中的lower_bound, upper_bound

2016-09-16 10:43:16 515

原创 120. Triangle

ProblemGiven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,

2016-09-14 09:19:12 185

原创 198. House Robber

ProblomYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent

2016-09-13 08:57:51 180

原创 快速排序(quicksort)

IT公司招人,无论笔试还是面试,快排基本上都会问到。通常情况下,快排实现有两个函数:void quickSort(int arr[], int left, int right);int partition(int arr[], int left, int right)快排采用divide-and-conquer策略:选一个pivot valuePartitionSort both par

2016-09-11 14:55:10 3733

原创 121. Best Time to Buy and Sell Stock

ProblemSay you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock

2016-09-09 17:37:44 184

原创 53. Maximum Subarray

最近迷恋DP,我看还是将这个主题先解决一些。ProblemFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous

2016-09-09 16:13:18 153

原创 300. Longest Increasing Subsequence

ProblemGiven an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], theref

2016-09-08 11:37:23 162

原创 63. Unique Paths II

ProblemFollow up for “Unique Paths”:Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid

2016-09-08 10:15:23 143

原创 62. Unique Paths

ProblemA robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach th

2016-09-07 17:30:46 155

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除