- 博客(60)
- 收藏
- 关注
原创 53. Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanati...
2018-10-31 21:07:24 239
原创 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at a...
2018-10-31 18:05:32 216
原创 70. Climbing Stairs
You are climbing a stair case. It takesnsteps 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?Note:Givennwill be a positive...
2018-10-31 17:05:43 263
原创 123. Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note: You may not e...
2018-10-31 15:46:29 227
原创 122. Best Time to Buy and Sell Stock II
Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy on...
2018-10-31 09:03:39 135
原创 121. Best Time to Buy and Sell Stock
Say 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 (i.e., buy one and sell one share of the stock),...
2018-10-31 08:36:56 137
原创 C++使用Boost 解析Json
1.下载Boost库。2.建立控制台项目。3.配置Boost路径。 项目属性 - C/C++ - 常规 - 附加包含目录 - 添加Boost库的路径。4.代码实例#include <boost/property_tree/ptree.hpp>#include <boost/property_tree/json_parser.hpp>#incl...
2018-10-30 17:32:33 2956
原创 Git 中的stash功能
stash可以把当前工作现场“保存”起来,等以后恢复现场后继续工作。演示如下:1.查看分支 有两个分支master和subWork,当前的工作分支是subWork。$ git branch master* subWork2.查看工作状态 当前分支subWork上的工作尚未完成,如果有另一项任务需要优先完成,或者出现BUG需要立刻修复。此时需要另外创建一个...
2018-10-29 12:59:29 40125 8
原创 Git 分支的创建与合并
1.查看分支 目前只有一个分支master,*表示当前分支。$ git branch* master2.创建分支 subWork是新创建的分支名称。$ git branch subWork3.切换分支 切换到分支subWork。$ git checkout subWork4.查看分支 目前有两个分支master 和subWor...
2018-10-28 20:40:31 277
原创 Git 建立远程仓库
1.创建SSH Key 在目录下运行上述命令,设置均按默认值,一路回车即可。 ssh-keygen -t rsa -C "email@example.com" 创建成功后会生成.ssh目录,里面有id_rsa和id_rsa.pub两个文件。其中,id_rsa是私钥,id_rsa.pub是公钥。2.GitHub上添加 SHH Key 注册GitHub账号,登录后打开S...
2018-10-28 14:32:08 385
原创 Git 添加和删除文件
1.添加文件 新增一个文件test.txt。$ touch test.txt 提交到暂存区。$ git add test.txt 提交到版本库。$ git commit -m "add file" 2.删除文件 删除一个文件test.txt。$ rm test.txt 从版本库删除该文件。$ git rm test...
2018-10-27 18:34:34 13895 1
原创 Git 撤销修改
1.工作区撤销修改 在工作中修改了readme.txt文件,现在撤销修改。$ git checkout -- readme.txt 命令中的--很重要,没有--,就变成了“切换到另一个分支”的命令。 撤销工作区所有文件的修改。$ git checkout .2.暂存区撤销修改 在工作中修改了readme.txt文件,将修改提交到暂存区。...
2018-10-27 17:44:33 289
原创 Git 版本回退
显示从近到远的提交日志。$ git log 如果输出的信息太多,加上参数--pretty=oneline。$ git log --pretty=oneline4e22fba9454c409bcf363f49089f936cc7e51690 modify filee400778c94f3ece7c3fffe1a9cdf6677dd04d578 delete file...
2018-10-27 16:09:00 561
原创 Git版本库的状态
1.修改文件 修改仓库里的文件readme.txt.$ vim readme.txt 修改后的文件内容如下:Welcome to git.Git is a version control system.Git is free. 运行git status 命令查看仓库的状态。$ git status On branch master Changed ...
2018-10-27 14:05:59 292
原创 Git 创建版本库
1.CentOS 6.5 安装Git$ yum -y install git2.查看Git版本$ git --version3.创建空目录 创建名称为work的空目录,pwd命令用于显示当前目录,我的CentOS上目录为/root/work$ mkdir work$ cd work$ pwd/root/work4.创建版本库 命令 # git...
2018-10-27 12:00:49 255
原创 .NET Core 使用 log4net
1.安装log4net 建立.NET Core工程 - 右键 - 管理NuGet程序包 - 搜索log4net - 安装。2.日志输出到控制台using log4net;using log4net.Config;using log4net.Repository;using System;namespace LogTest{ class Program...
2018-10-25 17:17:44 4801
原创 测试PostgreSQL行级锁
1.打开三个psql窗口,连接到postgreSQL数据库 查看窗口连接到的服务进程的pid。select pg_backend_pid(); 2.在第一个窗口更新一行数据mydb=# begin;BEGINmydb=# select * from student where id =1 for update;+----+-------+| i...
2018-10-25 15:29:20 2821
原创 postgreSQL中的virtualxid, transactionid, virtualtransaction
在postgreSQL中,描述事务ID的字段有三个:virtualxid, transactionid, virtualtransaction。它们的含义分别如下:名称 含义 virtualxid 虚拟事务ID。如果对象虚拟事务,则此值为null。 transactionid 事务ID。如果对象不是事务,则此值为mull。 virtualtransacti...
2018-10-25 12:09:25 3634
原创 测试postgreSQL中表锁
1.打开三个psql窗口,连接到postgreSQL数据库。 查看窗口连接到的服务进程的pid。select pg_backend_pid(); 三个窗口的pid分别如下: 2.在第一个窗口锁定一张表mydb=# begin;BEGINmydb=# lock table person;LOCK TABLE3.在第三个窗口查看数据库...
2018-10-25 11:38:50 1061
原创 postgreSQL中的内连接和外连接
1.建表 create table person ( presonId int, presonName varchar(20) ); create table city ( cityId int, cityName varchar(20) );2.插入数据 insert into person values(1,'April'),(3,'Harris...
2018-10-24 20:43:20 4322
原创 103. Binary Tree Zigzag Level Order Traversal
Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tre...
2018-10-24 09:38:18 251
原创 105. Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, givenpreorder = [3,9,20,15,7]inorder = [9,3...
2018-10-23 22:44:16 218
原创 106. Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, giveninorder = [9,3,15,20,7]postorder = [9...
2018-10-23 22:32:56 225
原创 107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,null,null,15,7...
2018-10-23 17:40:37 260
原创 102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 ...
2018-10-23 17:32:31 228
原创 101. Symmetric Tree
Given 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: 1 / \ 2 2 / \ / \3 4 4 3...
2018-10-23 14:07:12 253
原创 111. Minimum Depth of Binary Tree
Given 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.Note: A leaf is a node with no childre...
2018-10-22 21:53:00 212
原创 104. Maximum Depth of Binary Tree
Given 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.Note: A leaf is a node with no childre...
2018-10-22 21:11:34 291
原创 112. Path Sum
Given 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.Note: A leaf is a node with no children.Example:...
2018-10-22 20:06:09 228
原创 129. Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota...
2018-10-22 16:52:47 216
原创 100. Same Tree
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example ...
2018-10-22 14:17:12 299
原创 145. Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [3,2,1]Follow up: Recursive solution is trivial, could...
2018-10-22 13:52:30 224
原创 144. Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,2,3]Follow up: Recursive solution is trivial, could ...
2018-10-22 12:56:49 141
原创 94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,3,2]Follow up: Recursive solution is trivial, could y...
2018-10-22 11:23:48 136
原创 python多线程的Lock()
Lock用于锁定。job1和job2对同一个全局变量操作。import threadingdef job1(): global A,lock lock.acquire() for i in range(10): A+=1 print("job1",A) lock.release()def job2(): global A,lock lock....
2018-10-21 12:55:26 3804
原创 python多线程的queue()
queue可以传递多线程的结果,用以代替return。 下例中,输入4组数据,开启4个线程分别对数据进行计算,然后将结果放入queue中。线程结束后,在主线程中从queue中获取计算结果。import threadingimport time;from queue import Queue def job(vec,res): for i in range(len(v...
2018-10-21 11:22:01 4660
原创 python多线程中的join()
先看一个例子,该例子没用到join。 添加一个线程,输出“start”和“finish”标记线程的开始和结束。线程added_thread和线程main同时运行,其中added_thread消耗较长的时间(通过线程sleep模拟)。mian执行结束后,added_thread才执行完毕。import threadingimport time;def job(): ...
2018-10-21 11:20:35 2639
原创 python多线程基础
1.查询线程 输出线程的数目,枚举线程,输出当前线程。import threadingdef main(): print(threading.active_count()) print(threading.enumerate()) print(threading.current_thread())if __name__ == '__main__': ...
2018-10-21 11:14:57 286
原创 300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101]...
2018-10-17 23:11:01 107
原创 PostgreSQL中的两阶段提交
在分布式系统中,事务往往包含了多台数据库上的操作。多台数据库之间的原子性,需要通过两阶段提交协议来实现。 两阶段提交协议的步骤:(1)应用程序调用事务协调器中的提交方法。(2)事务协调器将联络事务中涉及的所有数据库,通知它们准备提交事务(PREPARE TRANSACTION)。(3)数据库收到通知后,确保后续在被要求提交事务时能提交,或在被要求回滚事务时能回滚,则返...
2018-10-17 18:29:35 3119
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人