This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://msdn.microsoft.com/zh-cn/library/system.diagnostics.stopwatch(v=vs.110).aspx | |
using System; | |
using System.Diagnostics; | |
using System.Threading; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Stopwatch stopWatch = new Stopwatch(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Definition for a binary tree node. | |
struct TreeNode { | |
int val; | |
TreeNode *left; | |
TreeNode *right; | |
TreeNode(int x) : val(x), left(nullptr), right(nullptr) { } | |
}; | |
// 使用先序遍历将二叉树转化为一个字符序列表示的二叉树 | |
void treeToSequence(TreeNode* root, string& result) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bitset> | |
#include <iostream> | |
using namespace std; | |
void outbin(const int x) { cout << bitset<sizeof(int) * 8>(x) << endl; } // 二进制输出 | |
void outoct(const int x) { cout << oct << x << endl; } // 八进制输出 | |
void outhex(const int x) { cout << hex << x << endl; } // 十六进制输出 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
/* | |
牛顿迭代法快速寻找平方根 | |
Ref: https://www.zhihu.com/question/20690553(详细介绍了牛顿-拉弗森方法的原理以及收敛的充分条件) | |
Ref: http://www.matrix67.com/blog/archives/361 | |
求根号 a,也就是求解 x^2 - a = 0 的非负解。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
时间测量 | |
使用 C++11 中的 chrono 库 | |
http://en.cppreference.com/w/cpp/chrono/duration/duration_cast | |
*/ | |
#include <chrono> |