|
|
<!DOCTYPE html>
|
|
|
<html lang="zh-Hans">
|
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
|
|
|
<meta name="theme-color" content="#222">
|
|
|
<meta name="generator" content="Hexo 4.2.0">
|
|
|
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
|
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
|
|
|
<link rel="mask-icon" href="/images/logo.svg" color="#222">
|
|
|
<meta name="google-site-verification" content="2X6S9P7CAjXjVvw8YyQR8pCu-B0oEu7O9quLgxXuWyA">
|
|
|
<meta name="baidu-site-verification" content="dV8JGNzi0c">
|
|
|
<meta name="chinaz-site-verification" content="500A176AA29CFB31">
|
|
|
|
|
|
<script data-ad-client="ca-pub-7480618470784058" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
|
|
|
|
|
<link rel="stylesheet" href="/css/main.css">
|
|
|
|
|
|
<link rel="stylesheet" href="//fonts.loli.net/css?family=Lato:300,300italic,400,400italic,700,700italic|M+ 2p:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
|
|
|
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
|
|
|
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
|
|
|
|
|
|
|
|
|
<script id="hexo-configurations">
|
|
|
var NexT = window.NexT || {};
|
|
|
var CONFIG = {
|
|
|
hostname: new URL('https://nicksxs.me').hostname,
|
|
|
root: '/',
|
|
|
scheme: 'Pisces',
|
|
|
version: '7.7.0',
|
|
|
exturl: false,
|
|
|
sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
|
|
|
copycode: {"enable":true,"show_result":false,"style":null},
|
|
|
back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
|
|
|
bookmark: {"enable":false,"color":"#222","save":"auto"},
|
|
|
fancybox: true,
|
|
|
mediumzoom: false,
|
|
|
lazyload: true,
|
|
|
pangu: false,
|
|
|
comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
|
|
|
algolia: {
|
|
|
appID: '',
|
|
|
apiKey: '',
|
|
|
indexName: '',
|
|
|
hits: {"per_page":10},
|
|
|
labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
|
|
|
},
|
|
|
localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
|
|
|
path: '',
|
|
|
motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<meta name="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
<meta property="og:type" content="website">
|
|
|
<meta property="og:title" content="Nicksxs's Blog">
|
|
|
<meta property="og:url" content="https://nicksxs.me/page/4/index.html">
|
|
|
<meta property="og:site_name" content="Nicksxs's Blog">
|
|
|
<meta property="og:description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
<meta property="article:author" content="Nicksxs">
|
|
|
<meta property="article:tag" content="Nicksxs">
|
|
|
<meta property="article:tag" content="史学森">
|
|
|
<meta property="article:tag" content="米方方">
|
|
|
<meta property="article:tag" content="米方方的男朋友">
|
|
|
<meta property="article:tag" content="森哥">
|
|
|
<meta name="twitter:card" content="summary">
|
|
|
|
|
|
<link rel="canonical" href="https://nicksxs.me/page/4/">
|
|
|
|
|
|
|
|
|
<script id="page-configurations">
|
|
|
// https://hexo.io/docs/variables.html
|
|
|
CONFIG.page = {
|
|
|
sidebar: "",
|
|
|
isHome: true,
|
|
|
isPost: false
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<title>Nicksxs's Blog</title>
|
|
|
|
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-61358619-1"></script>
|
|
|
<script>
|
|
|
if (CONFIG.hostname === location.hostname) {
|
|
|
window.dataLayer = window.dataLayer || [];
|
|
|
function gtag(){dataLayer.push(arguments);}
|
|
|
gtag('js', new Date());
|
|
|
gtag('config', 'UA-61358619-1');
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
|
|
|
<script>
|
|
|
var _hmt = _hmt || [];
|
|
|
(function() {
|
|
|
var hm = document.createElement("script");
|
|
|
hm.src = "https://hm.baidu.com/hm.js?20f33b3c0c0eff9b1522999c0015646d";
|
|
|
var s = document.getElementsByTagName("script")[0];
|
|
|
s.parentNode.insertBefore(hm, s);
|
|
|
})();
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<noscript>
|
|
|
<style>
|
|
|
.use-motion .brand,
|
|
|
.use-motion .menu-item,
|
|
|
.sidebar-inner,
|
|
|
.use-motion .post-block,
|
|
|
.use-motion .pagination,
|
|
|
.use-motion .comments,
|
|
|
.use-motion .post-header,
|
|
|
.use-motion .post-body,
|
|
|
.use-motion .collection-header { opacity: initial; }
|
|
|
|
|
|
.use-motion .site-title,
|
|
|
.use-motion .site-subtitle {
|
|
|
opacity: initial;
|
|
|
top: initial;
|
|
|
}
|
|
|
|
|
|
.use-motion .logo-line-before i { left: initial; }
|
|
|
.use-motion .logo-line-after i { right: initial; }
|
|
|
</style>
|
|
|
</noscript>
|
|
|
|
|
|
<link rel="alternate" href="/atom.xml" title="Nicksxs's Blog" type="application/atom+xml">
|
|
|
</head>
|
|
|
|
|
|
<body itemscope itemtype="http://schema.org/WebPage">
|
|
|
<div class="container use-motion">
|
|
|
<div class="headband"></div>
|
|
|
|
|
|
<header class="header" itemscope itemtype="http://schema.org/WPHeader">
|
|
|
<div class="header-inner"><div class="site-brand-container">
|
|
|
<div class="site-meta">
|
|
|
|
|
|
<div>
|
|
|
<a href="/" class="brand" rel="start">
|
|
|
<span class="logo-line-before"><i></i></span>
|
|
|
<span class="site-title">Nicksxs's Blog</span>
|
|
|
<span class="logo-line-after"><i></i></span>
|
|
|
</a>
|
|
|
</div>
|
|
|
<p class="site-subtitle">What hurts more, the pain of hard work or the pain of regret?</p>
|
|
|
</div>
|
|
|
|
|
|
<div class="site-nav-toggle">
|
|
|
<div class="toggle" aria-label="Toggle navigation bar">
|
|
|
<span class="toggle-line toggle-line-first"></span>
|
|
|
<span class="toggle-line toggle-line-middle"></span>
|
|
|
<span class="toggle-line toggle-line-last"></span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<nav class="site-nav">
|
|
|
|
|
|
<ul id="menu" class="menu">
|
|
|
<li class="menu-item menu-item-home">
|
|
|
|
|
|
<a href="/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-about">
|
|
|
|
|
|
<a href="/about/" rel="section"><i class="fa fa-fw fa-about"></i>About</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-tags">
|
|
|
|
|
|
<a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>Tags</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-categories">
|
|
|
|
|
|
<a href="/categories/" rel="section"><i class="fa fa-fw fa-categories"></i>Categories</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-archives">
|
|
|
|
|
|
<a href="/archives/" rel="section"><i class="fa fa-fw fa-archives"></i>Archives</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-sitemap">
|
|
|
|
|
|
<a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>Sitemap</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-commonweal">
|
|
|
|
|
|
<a href="/404/" rel="section"><i class="fa fa-fw fa-heartbeat"></i>Commonweal 404</a>
|
|
|
|
|
|
</li>
|
|
|
</ul>
|
|
|
|
|
|
</nav>
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
<div class="back-to-top">
|
|
|
<i class="fa fa-arrow-up"></i>
|
|
|
<span>0%</span>
|
|
|
</div>
|
|
|
|
|
|
<a href="https://github.com/nicksxs" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>
|
|
|
|
|
|
|
|
|
<main class="main">
|
|
|
<div class="main-inner">
|
|
|
<div class="content-wrap">
|
|
|
|
|
|
|
|
|
<div class="content">
|
|
|
|
|
|
|
|
|
<div class="posts-expand">
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2016/07/13/swoole-websocket-test/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h1 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2016/07/13/swoole-websocket-test/" class="post-title-link" itemprop="url">swoole-websocket-test</a>
|
|
|
</h1>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2016-07-13 22:59:23" itemprop="dateCreated datePublished" datetime="2016-07-13T22:59:23+08:00">2016-07-13</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-check-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:26" itemprop="dateModified" datetime="2020-01-12T21:08:26+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-folder-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/php/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">php</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2016/07/13/swoole-websocket-test/" class="post-meta-item leancloud_visitors" data-flag-title="swoole-websocket-test" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-comment-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2016/07/13/swoole-websocket-test/#comments" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2016/07/13/swoole-websocket-test/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<h3 id="玩一下swoole的websocket"><a href="#玩一下swoole的websocket" class="headerlink" title="玩一下swoole的websocket"></a>玩一下swoole的websocket</h3><p>WebSocket是HTML5开始提供的一种在单个<a href="https://zh.wikipedia.org/wiki/TCP" target="_blank" rel="noopener">TCP</a>连接上进行<a href="https://zh.wikipedia.org/wiki/%E5%85%A8%E9%9B%99%E5%B7%A5" target="_blank" rel="noopener">全双工</a>通讯的协议。WebSocket通信协议于2011年被<a href="https://zh.wikipedia.org/wiki/Internet_Engineering_Task_Force" target="_blank" rel="noopener">IETF</a>定为标准RFC 6455,WebSocketAPI被W3C定为标准。<br>,在web私信,im等应用较多。背景和优缺点可以参看<a href="https://zh.wikipedia.org/wiki/WebSocket" target="_blank" rel="noopener">wiki</a>。</p>
|
|
|
<h3 id="环境准备"><a href="#环境准备" class="headerlink" title="环境准备"></a>环境准备</h3><p>因为swoole官方还不支持windows,所以需要装下linux,之前都是用ubuntu,<br>这次就试一下centos7,还是满好看的,虽然虚拟机会默认最小安装,需要在安装<br>时自己选择带gnome的,当然最小安装也是可以的,只是最后需要改下防火墙。<br>然后是装下PHP,Nginx什么的,我是用<a href="https://oneinstack.com/" target="_blank" rel="noopener">Oneinstack</a>,可以按需安装<br>给做这个的大大点个赞。</p>
|
|
|
<!--noindex-->
|
|
|
<div class="post-button">
|
|
|
<a class="btn" href="/2016/07/13/swoole-websocket-test/#more" rel="contents">
|
|
|
Read more »
|
|
|
</a>
|
|
|
</div>
|
|
|
<!--/noindex-->
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2015/06/22/invert-binary-tree/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h1 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2015/06/22/invert-binary-tree/" class="post-title-link" itemprop="url">invert-binary-tree</a>
|
|
|
</h1>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2015-06-22 10:29:44" itemprop="dateCreated datePublished" datetime="2015-06-22T10:29:44+08:00">2015-06-22</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-check-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:26" itemprop="dateModified" datetime="2020-01-12T21:08:26+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-folder-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/leetcode/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">leetcode</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2015/06/22/invert-binary-tree/" class="post-meta-item leancloud_visitors" data-flag-title="invert-binary-tree" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-comment-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2015/06/22/invert-binary-tree/#comments" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2015/06/22/invert-binary-tree/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<p><strong>Invert a binary tree</strong></p>
|
|
|
<pre><code> 4
|
|
|
/ \
|
|
|
2 7
|
|
|
/ \ / \
|
|
|
1 3 6 9</code></pre><p>to</p>
|
|
|
<pre><code> 4
|
|
|
/ \
|
|
|
7 2
|
|
|
/ \ / \
|
|
|
9 6 3 1</code></pre><p><strong>Trivia:</strong><br>This problem was inspired by <a href="https://twitter.com/mxcl/status/608682016205344768" target="_blank" rel="noopener">this original tweet</a> by <a href="https://twitter.com/mxcl" target="_blank" rel="noopener">Max Howell</a>:</p>
|
|
|
<blockquote>
|
|
|
<p>Google: 90% of our engineers use the software you wrote (Homebrew),<br>but you can’t invert a binary tree on a whiteboard so fuck off. </p>
|
|
|
</blockquote>
|
|
|
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Definition for a binary tree node.</span></span><br><span class="line"><span class="comment"> * struct TreeNode {</span></span><br><span class="line"><span class="comment"> * int val;</span></span><br><span class="line"><span class="comment"> * TreeNode *left;</span></span><br><span class="line"><span class="comment"> * TreeNode *right;</span></span><br><span class="line"><span class="comment"> * TreeNode(int x) : val(x), left(NULL), right(NULL) {}</span></span><br><span class="line"><span class="comment"> * };</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Solution</span> {</span></span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line"> <span class="function">TreeNode* <span class="title">invertTree</span><span class="params">(TreeNode* root)</span> </span>{</span><br><span class="line"> <span class="keyword">if</span>(root == <span class="literal">NULL</span>) <span class="keyword">return</span> root;</span><br><span class="line"> TreeNode* temp;</span><br><span class="line"> temp = invertTree(root->left);</span><br><span class="line"> root->left = invertTree(root->right);</span><br><span class="line"> root->right = temp;</span><br><span class="line"> <span class="keyword">return</span> root;</span><br><span class="line"> }</span><br><span class="line">};</span><br></pre></td></tr></table></figure>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2015/04/15/Leetcode-No-3/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h1 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2015/04/15/Leetcode-No-3/" class="post-title-link" itemprop="url">leetcode no.3</a>
|
|
|
</h1>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2015-04-15 13:49:00" itemprop="dateCreated datePublished" datetime="2015-04-15T13:49:00+08:00">2015-04-15</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-check-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:26" itemprop="dateModified" datetime="2020-01-12T21:08:26+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-folder-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/leetcode/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">leetcode</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2015/04/15/Leetcode-No-3/" class="post-meta-item leancloud_visitors" data-flag-title="leetcode no.3" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-comment-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2015/04/15/Leetcode-No-3/#comments" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2015/04/15/Leetcode-No-3/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<p>*<em>Longest Substring Without Repeating Characters *</em></p>
|
|
|
<!--noindex-->
|
|
|
<div class="post-button">
|
|
|
<a class="btn" href="/2015/04/15/Leetcode-No-3/#more" rel="contents">
|
|
|
Read more »
|
|
|
</a>
|
|
|
</div>
|
|
|
<!--/noindex-->
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2015/04/14/Add-Two-Number/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h1 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2015/04/14/Add-Two-Number/" class="post-title-link" itemprop="url">add-two-number</a>
|
|
|
</h1>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2015-04-14 17:40:10" itemprop="dateCreated datePublished" datetime="2015-04-14T17:40:10+08:00">2015-04-14</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-check-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:27" itemprop="dateModified" datetime="2020-01-12T21:08:27+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-folder-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/leetcode/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">leetcode</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2015/04/14/Add-Two-Number/" class="post-meta-item leancloud_visitors" data-flag-title="add-two-number" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-comment-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2015/04/14/Add-Two-Number/#comments" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2015/04/14/Add-Two-Number/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<h3 id="problem"><a href="#problem" class="headerlink" title="problem"></a>problem</h3><p>You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.</p>
|
|
|
<p><strong>Input</strong>:<code>(2 -> 4 -> 3) + (5 -> 6 -> 4)</code><br><strong>Output</strong>: <code>7 -> 0 -> 8</code></p>
|
|
|
<p><strong>分析(不用英文装逼了)</strong><br>这个代码是抄来的,<a href="https://github.com/haoel/leetcode" target="_blank" rel="noopener">链接</a>原作是这位大大。</p>
|
|
|
<!--noindex-->
|
|
|
<div class="post-button">
|
|
|
<a class="btn" href="/2015/04/14/Add-Two-Number/#more" rel="contents">
|
|
|
Read more »
|
|
|
</a>
|
|
|
</div>
|
|
|
<!--/noindex-->
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2015/03/13/Reverse-Integer/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h1 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2015/03/13/Reverse-Integer/" class="post-title-link" itemprop="url">Reverse Integer</a>
|
|
|
</h1>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2015-03-13 17:22:20" itemprop="dateCreated datePublished" datetime="2015-03-13T17:22:20+08:00">2015-03-13</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-check-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:27" itemprop="dateModified" datetime="2020-01-12T21:08:27+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-folder-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/leetcode/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">leetcode</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2015/03/13/Reverse-Integer/" class="post-meta-item leancloud_visitors" data-flag-title="Reverse Integer" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-comment-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2015/03/13/Reverse-Integer/#comments" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2015/03/13/Reverse-Integer/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<h3 id="Reverse-Integer"><a href="#Reverse-Integer" class="headerlink" title="Reverse Integer"></a><a href="https://leetcode.com/problems/reverse-integer/" target="_blank" rel="noopener">Reverse Integer</a></h3><h4 id="Reverse-digits-of-an-integer"><a href="#Reverse-digits-of-an-integer" class="headerlink" title="Reverse digits of an integer."></a>Reverse digits of an integer.</h4><p>Example1: x = 123, return 321<br>Example2: x = -123, return -321</p>
|
|
|
<!--noindex-->
|
|
|
<div class="post-button">
|
|
|
<a class="btn" href="/2015/03/13/Reverse-Integer/#more" rel="contents">
|
|
|
Read more »
|
|
|
</a>
|
|
|
</div>
|
|
|
<!--/noindex-->
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2015/03/11/Reverse-Bits/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h1 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2015/03/11/Reverse-Bits/" class="post-title-link" itemprop="url">Reverse Bits</a>
|
|
|
</h1>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2015-03-11 17:35:20" itemprop="dateCreated datePublished" datetime="2015-03-11T17:35:20+08:00">2015-03-11</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-check-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:27" itemprop="dateModified" datetime="2020-01-12T21:08:27+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-folder-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/leetcode/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">leetcode</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2015/03/11/Reverse-Bits/" class="post-meta-item leancloud_visitors" data-flag-title="Reverse Bits" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-comment-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2015/03/11/Reverse-Bits/#comments" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2015/03/11/Reverse-Bits/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<h3 id="Reverse-Bits"><a href="#Reverse-Bits" class="headerlink" title="Reverse Bits "></a><a href="https://leetcode.com/problems/reverse-bits/" target="_blank" rel="noopener">Reverse Bits </a></h3><h4 id="Reverse-bits-of-a-given-32-bits-unsigned-integer"><a href="#Reverse-bits-of-a-given-32-bits-unsigned-integer" class="headerlink" title="Reverse bits of a given 32 bits unsigned integer."></a>Reverse bits of a given 32 bits unsigned integer.</h4><p>For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000).</p>
|
|
|
<!--noindex-->
|
|
|
<div class="post-button">
|
|
|
<a class="btn" href="/2015/03/11/Reverse-Bits/#more" rel="contents">
|
|
|
Read more »
|
|
|
</a>
|
|
|
</div>
|
|
|
<!--/noindex-->
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2015/03/11/Number-Of-1-Bits/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h1 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2015/03/11/Number-Of-1-Bits/" class="post-title-link" itemprop="url">Number of 1 Bits</a>
|
|
|
</h1>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2015-03-11 17:02:58" itemprop="dateCreated datePublished" datetime="2015-03-11T17:02:58+08:00">2015-03-11</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-check-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:26" itemprop="dateModified" datetime="2020-01-12T21:08:26+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-folder-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/leetcode/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">leetcode</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2015/03/11/Number-Of-1-Bits/" class="post-meta-item leancloud_visitors" data-flag-title="Number of 1 Bits" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-comment-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2015/03/11/Number-Of-1-Bits/#comments" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2015/03/11/Number-Of-1-Bits/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<h3 id="Number-of-1-Bits"><a href="#Number-of-1-Bits" class="headerlink" title="Number of 1 Bits "></a><a href="https://leetcode.com/problems/number-of-1-bits/" target="_blank" rel="noopener">Number of 1 Bits </a></h3><h4 id="Write-a-function-that-takes-an-unsigned-integer-and-returns-the-number-of-’1’-bits-it-has-also-known-as-the-Hamming-weight-For-example-the-32-bit-integer-‘11’-has-binary-representation-00000000000000000000000000001011-so-the-function-should-return-3"><a href="#Write-a-function-that-takes-an-unsigned-integer-and-returns-the-number-of-’1’-bits-it-has-also-known-as-the-Hamming-weight-For-example-the-32-bit-integer-‘11’-has-binary-representation-00000000000000000000000000001011-so-the-function-should-return-3" class="headerlink" title="Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight). For example, the 32-bit integer ‘11’ has binary representation 00000000000000000000000000001011, so the function should return 3."></a>Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight). For example, the 32-bit integer ‘11’ has binary representation <code>00000000000000000000000000001011</code>, so the function should return 3.</h4>
|
|
|
<!--noindex-->
|
|
|
<div class="post-button">
|
|
|
<a class="btn" href="/2015/03/11/Number-Of-1-Bits/#more" rel="contents">
|
|
|
Read more »
|
|
|
</a>
|
|
|
</div>
|
|
|
<!--/noindex-->
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2015/01/16/pcre-intro-and-a-simple-package/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h1 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2015/01/16/pcre-intro-and-a-simple-package/" class="post-title-link" itemprop="url">pcre-intro-and-a-simple-package</a>
|
|
|
</h1>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2015-01-16 14:30:20" itemprop="dateCreated datePublished" datetime="2015-01-16T14:30:20+08:00">2015-01-16</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-check-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:26" itemprop="dateModified" datetime="2020-01-12T21:08:26+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-folder-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/C/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">C++</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2015/01/16/pcre-intro-and-a-simple-package/" class="post-meta-item leancloud_visitors" data-flag-title="pcre-intro-and-a-simple-package" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-comment-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2015/01/16/pcre-intro-and-a-simple-package/#comments" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2015/01/16/pcre-intro-and-a-simple-package/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<h3 id="Pcre"><a href="#Pcre" class="headerlink" title="Pcre"></a><a href="http://www.pcre.org/" target="_blank" rel="noopener">Pcre</a></h3><blockquote>
|
|
|
<p>Perl Compatible Regular Expressions (PCRE) is a regular<br> expression C library inspired by the regular expression<br> capabilities in the Perl programming language, written<br> by Philip Hazel, starting in summer 1997.</p>
|
|
|
</blockquote>
|
|
|
<p>因为最近工作内容的一部分需要做字符串的识别处理,所以就顺便用上了之前在PHP中用过的正则,在C/C++中本身不包含正则库,这里使用的pcre,对MFC开发,在<a href="http://www.psyon.org/projects/pcre-win32/index.php" target="_blank" rel="noopener">这里</a>提供了静态链接库,在引入lib跟.h文件后即可使用。</p>
|
|
|
<!--noindex-->
|
|
|
<div class="post-button">
|
|
|
<a class="btn" href="/2015/01/16/pcre-intro-and-a-simple-package/#more" rel="contents">
|
|
|
Read more »
|
|
|
</a>
|
|
|
</div>
|
|
|
<!--/noindex-->
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2015/01/14/Two-Sum/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h1 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2015/01/14/Two-Sum/" class="post-title-link" itemprop="url">two sum</a>
|
|
|
</h1>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2015-01-14 15:39:31" itemprop="dateCreated datePublished" datetime="2015-01-14T15:39:31+08:00">2015-01-14</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-check-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:27" itemprop="dateModified" datetime="2020-01-12T21:08:27+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-folder-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/leetcode/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">leetcode</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2015/01/14/Two-Sum/" class="post-meta-item leancloud_visitors" data-flag-title="two sum" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-comment-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2015/01/14/Two-Sum/#comments" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2015/01/14/Two-Sum/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<h3 id="problem"><a href="#problem" class="headerlink" title="problem"></a>problem</h3><p>Given an array of integers, find two numbers such that they add up to a specific target number.</p>
|
|
|
<p>The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.</p>
|
|
|
<!--noindex-->
|
|
|
<div class="post-button">
|
|
|
<a class="btn" href="/2015/01/14/Two-Sum/#more" rel="contents">
|
|
|
Read more »
|
|
|
</a>
|
|
|
</div>
|
|
|
<!--/noindex-->
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2015/01/04/Path-Sum/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h1 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2015/01/04/Path-Sum/" class="post-title-link" itemprop="url">Path Sum</a>
|
|
|
</h1>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2015-01-04 15:44:10" itemprop="dateCreated datePublished" datetime="2015-01-04T15:44:10+08:00">2015-01-04</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-check-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:26" itemprop="dateModified" datetime="2020-01-12T21:08:26+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-folder-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/leetcode/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">leetcode</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2015/01/04/Path-Sum/" class="post-meta-item leancloud_visitors" data-flag-title="Path Sum" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-comment-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2015/01/04/Path-Sum/#comments" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2015/01/04/Path-Sum/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<h3 id="problem"><a href="#problem" class="headerlink" title="problem"></a>problem</h3><p>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.</p>
|
|
|
<!--noindex-->
|
|
|
<div class="post-button">
|
|
|
<a class="btn" href="/2015/01/04/Path-Sum/#more" rel="contents">
|
|
|
Read more »
|
|
|
</a>
|
|
|
</div>
|
|
|
<!--/noindex-->
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<nav class="pagination">
|
|
|
<a class="extend prev" rel="prev" href="/page/3/"><i class="fa fa-angle-left" aria-label="Previous page"></i></a><a class="page-number" href="/">1</a><span class="space">…</span><a class="page-number" href="/page/3/">3</a><span class="page-number current">4</span><a class="page-number" href="/page/5/">5</a><a class="extend next" rel="next" href="/page/5/"><i class="fa fa-angle-right" aria-label="Next page"></i></a>
|
|
|
</nav>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<script>
|
|
|
window.addEventListener('tabs:register', () => {
|
|
|
let activeClass = CONFIG.comments.activeClass;
|
|
|
if (CONFIG.comments.storage) {
|
|
|
activeClass = localStorage.getItem('comments_active') || activeClass;
|
|
|
}
|
|
|
if (activeClass) {
|
|
|
let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
|
|
|
if (activeTab) {
|
|
|
activeTab.click();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
if (CONFIG.comments.storage) {
|
|
|
window.addEventListener('tabs:click', event => {
|
|
|
if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
|
|
|
let commentClass = event.target.classList[1];
|
|
|
localStorage.setItem('comments_active', commentClass);
|
|
|
});
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<div class="toggle sidebar-toggle">
|
|
|
<span class="toggle-line toggle-line-first"></span>
|
|
|
<span class="toggle-line toggle-line-middle"></span>
|
|
|
<span class="toggle-line toggle-line-last"></span>
|
|
|
</div>
|
|
|
|
|
|
<aside class="sidebar">
|
|
|
<div class="sidebar-inner">
|
|
|
|
|
|
<ul class="sidebar-nav motion-element">
|
|
|
<li class="sidebar-nav-toc">
|
|
|
Table of Contents
|
|
|
</li>
|
|
|
<li class="sidebar-nav-overview">
|
|
|
Overview
|
|
|
</li>
|
|
|
</ul>
|
|
|
|
|
|
<!--noindex-->
|
|
|
<div class="post-toc-wrap sidebar-panel">
|
|
|
</div>
|
|
|
<!--/noindex-->
|
|
|
|
|
|
<div class="site-overview-wrap sidebar-panel">
|
|
|
<div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<img class="site-author-image" itemprop="image" alt="Nicksxs"
|
|
|
src="/uploads/avatar.jpg">
|
|
|
<p class="site-author-name" itemprop="name">Nicksxs</p>
|
|
|
<div class="site-description" itemprop="description">learn from zero,技术博客,Nicksxs,史学森</div>
|
|
|
</div>
|
|
|
<div class="site-state-wrap motion-element">
|
|
|
<nav class="site-state">
|
|
|
<div class="site-state-item site-state-posts">
|
|
|
<a href="/archives/">
|
|
|
|
|
|
<span class="site-state-item-count">43</span>
|
|
|
<span class="site-state-item-name">posts</span>
|
|
|
</a>
|
|
|
</div>
|
|
|
<div class="site-state-item site-state-categories">
|
|
|
<a href="/categories/">
|
|
|
|
|
|
<span class="site-state-item-count">33</span>
|
|
|
<span class="site-state-item-name">categories</span></a>
|
|
|
</div>
|
|
|
<div class="site-state-item site-state-tags">
|
|
|
<a href="/tags/">
|
|
|
|
|
|
<span class="site-state-item-count">53</span>
|
|
|
<span class="site-state-item-name">tags</span></a>
|
|
|
</div>
|
|
|
</nav>
|
|
|
</div>
|
|
|
<div class="links-of-author motion-element">
|
|
|
<span class="links-of-author-item">
|
|
|
<a href="https://github.com/nicksxs" title="GitHub → https://github.com/nicksxs" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
|
|
|
</span>
|
|
|
<span class="links-of-author-item">
|
|
|
<a href="mailto:nicksxs1202@gmail.com" title="E-Mail → mailto:nicksxs1202@gmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
|
|
|
</span>
|
|
|
<span class="links-of-author-item">
|
|
|
<a href="/atom.xml" title="RSS → /atom.xml"><i class="fa fa-fw fa-rss"></i>RSS</a>
|
|
|
</span>
|
|
|
</div>
|
|
|
<div class="cc-license motion-element" itemprop="license">
|
|
|
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
|
|
|
</div>
|
|
|
|
|
|
<script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script>
|
|
|
<script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script>
|
|
|
<div class="widget-wrap">
|
|
|
<div id="myCanvasContainer" class="widget tagcloud">
|
|
|
<canvas width="250" height="250" id="resCanvas" style="width=100%">
|
|
|
<ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/2019/" rel="tag">2019</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/" rel="tag">C</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/" rel="tag">C++</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Design-Patterns/" rel="tag">Design Patterns</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Distributed-Lock/" rel="tag">Distributed Lock</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Docker/" rel="tag">Docker</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Dockerfile/" rel="tag">Dockerfile</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/G1/" rel="tag">G1</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/GC/" rel="tag">GC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Garbage-First-Collector/" rel="tag">Garbage-First Collector</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Gogs/" rel="tag">Gogs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JVM/" rel="tag">JVM</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java/" rel="tag">Java</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Maven/" rel="tag">Maven</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Redis/" rel="tag">Redis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Singleton/" rel="tag">Singleton</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Webhook/" rel="tag">Webhook</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/aqs/" rel="tag">aqs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/" rel="tag">c++</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cgroup/" rel="tag">cgroup</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cluster/" rel="tag">cluster</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/" rel="tag">docker</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/echo/" rel="tag">echo</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hadoop/" rel="tag">hadoop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/im/" rel="tag">im</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/" rel="tag">java</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/leetcode/" rel="tag">leetcode</a><span class="tag-list-count">13</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/" rel="tag">linux</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mfc/" rel="tag">mfc</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mq/" rel="tag">mq</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql/" rel="tag">mysql</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/namespace/" rel="tag">namespace</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/" rel="tag">nginx</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/openresty/" rel="tag">openresty</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/php/" rel="tag">php</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/" rel="tag">python</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/" rel="tag">redis</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spark/" rel="tag">spark</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/swoole/" rel="tag">swoole</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/uname/" rel="tag">uname</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/websocket/" rel="tag">websocket</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81/" rel="tag">分布式锁</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%95%E4%BE%8B/" rel="tag">单例</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%9A%E5%AE%A2%EF%BC%8C%E6%96%87%E7%AB%A0/" rel="tag">博客,文章</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8F%91%E8%A1%8C%E7%89%88/" rel="tag">发行版</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%AF%84%E7%94%9F%E8%99%AB/" rel="tag">寄生虫</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%B4%E7%BB%88%E6%80%BB%E7%BB%93/" rel="tag">年终总结</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BD%B1%E8%AF%84/" rel="tag">影评</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" rel="tag">数据结构</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%BA%90%E7%A0%81/" rel="tag">源码</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%94%9F%E6%B4%BB/" rel="tag">生活</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" rel="tag">设计模式</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%AF%BB%E5%90%8E%E6%84%9F/" rel="tag">读后感</a><span class="tag-list-count">1</span></li></ul>
|
|
|
</canvas>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="links-of-blogroll motion-element">
|
|
|
<div class="links-of-blogroll-title">
|
|
|
<i class="fa fa-fw fa-link"></i>
|
|
|
Links
|
|
|
</div>
|
|
|
<ul class="links-of-blogroll-list">
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="http://www.zipperary.com/" title="http://www.zipperary.com/" rel="noopener" target="_blank">Zippera's blog</a>
|
|
|
</li>
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="http://x20a.xyz/" title="http://x20a.xyz/" rel="noopener" target="_blank">Freedom</a>
|
|
|
</li>
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="http://samuel.group/" title="http://samuel.group/" rel="noopener" target="_blank">sfwtt</a>
|
|
|
</li>
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="http://blog.leanote.com/buru" title="http://blog.leanote.com/buru" rel="noopener" target="_blank">bruce</a>
|
|
|
</li>
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="http://m2shad0w.com/" title="http://m2shad0w.com/" rel="noopener" target="_blank">m2shad0w</a>
|
|
|
</li>
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="http://www.programcat.com/" title="http://www.programcat.com" rel="noopener" target="_blank">程序喵的厨房</a>
|
|
|
</li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
</aside>
|
|
|
<div id="sidebar-dimmer"></div>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</main>
|
|
|
|
|
|
<footer class="footer">
|
|
|
<div class="footer-inner">
|
|
|
|
|
|
|
|
|
<div class="copyright">
|
|
|
|
|
|
©
|
|
|
<span itemprop="copyrightYear">2020</span>
|
|
|
<span class="with-love">
|
|
|
<i class="fa fa-user"></i>
|
|
|
</span>
|
|
|
<span class="author" itemprop="copyrightHolder">Nicksxs</span>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
function leancloudSelector(url) {
|
|
|
url = encodeURI(url);
|
|
|
return document.getElementById(url).querySelector('.leancloud-visitors-count');
|
|
|
}
|
|
|
if (CONFIG.page.isPost) {
|
|
|
function addCount(Counter) {
|
|
|
var visitors = document.querySelector('.leancloud_visitors');
|
|
|
var url = decodeURI(visitors.getAttribute('id'));
|
|
|
var title = visitors.getAttribute('data-flag-title');
|
|
|
|
|
|
Counter('get', `/classes/Counter?where=${JSON.stringify({ url })}`)
|
|
|
.then(response => response.json())
|
|
|
.then(({ results }) => {
|
|
|
if (results.length > 0) {
|
|
|
var counter = results[0];
|
|
|
Counter('put', '/classes/Counter/' + counter.objectId, { time: { '__op': 'Increment', 'amount': 1 } })
|
|
|
.then(response => response.json())
|
|
|
.then(() => {
|
|
|
leancloudSelector(url).innerText = counter.time + 1;
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.error('Failed to save visitor count', error);
|
|
|
})
|
|
|
} else {
|
|
|
leancloudSelector(url).innerText = 'Counter not initialized! More info at console err msg.';
|
|
|
console.error('ATTENTION! LeanCloud counter has security bug, see how to solve it here: https://github.com/theme-next/hexo-leancloud-counter-security. \n However, you can still use LeanCloud without security, by setting `security` option to `false`.');
|
|
|
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.error('LeanCloud Counter Error', error);
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
function showTime(Counter) {
|
|
|
var visitors = document.querySelectorAll('.leancloud_visitors');
|
|
|
var entries = [...visitors].map(element => {
|
|
|
return decodeURI(element.getAttribute('id'));
|
|
|
});
|
|
|
|
|
|
Counter('get', `/classes/Counter?where=${JSON.stringify({ url: { '$in': entries } })}`)
|
|
|
.then(response => response.json())
|
|
|
.then(({ results }) => {
|
|
|
if (results.length === 0) {
|
|
|
document.querySelectorAll('.leancloud_visitors .leancloud-visitors-count').forEach(element => {
|
|
|
element.innerText = 0;
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
for (let item of results) {
|
|
|
let { url, time } = item;
|
|
|
leancloudSelector(url).innerText = time;
|
|
|
}
|
|
|
for (let url of entries) {
|
|
|
var element = leancloudSelector(url);
|
|
|
if (element.innerText == '') {
|
|
|
element.innerText = 0;
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.error('LeanCloud Counter Error', error);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
fetch('https://app-router.leancloud.cn/2/route?appId=ysza182Vghlqjdt7QiwGLLJy-gzGzoHsz')
|
|
|
.then(response => response.json())
|
|
|
.then(({ api_server }) => {
|
|
|
var Counter = (method, url, data) => {
|
|
|
return fetch(`https://${api_server}/1.1${url}`, {
|
|
|
method: method,
|
|
|
headers: {
|
|
|
'X-LC-Id': 'ysza182Vghlqjdt7QiwGLLJy-gzGzoHsz',
|
|
|
'X-LC-Key': 's9GDqbn7gnGGkusf66YRVccw',
|
|
|
'Content-Type': 'application/json',
|
|
|
},
|
|
|
body: JSON.stringify(data)
|
|
|
});
|
|
|
};
|
|
|
if (CONFIG.page.isPost) {
|
|
|
if (CONFIG.hostname !== location.hostname) return;
|
|
|
addCount(Counter);
|
|
|
} else if (document.querySelectorAll('.post-title-link').length >= 1) {
|
|
|
showTime(Counter);
|
|
|
}
|
|
|
});
|
|
|
</script>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</footer>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<script src="/lib/anime.min.js"></script>
|
|
|
<script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
|
|
|
<script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
|
|
|
<script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>
|
|
|
<script src="/lib/velocity/velocity.min.js"></script>
|
|
|
<script src="/lib/velocity/velocity.ui.min.js"></script>
|
|
|
|
|
|
<script src="/js/utils.js"></script>
|
|
|
|
|
|
<script src="/js/motion.js"></script>
|
|
|
|
|
|
|
|
|
<script src="/js/schemes/pisces.js"></script>
|
|
|
|
|
|
|
|
|
<script src="/js/next-boot.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
(function(){
|
|
|
var bp = document.createElement('script');
|
|
|
var curProtocol = window.location.protocol.split(':')[0];
|
|
|
bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
|
|
|
var s = document.getElementsByTagName("script")[0];
|
|
|
s.parentNode.insertBefore(bp, s);
|
|
|
})();
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
function loadCount() {
|
|
|
var d = document, s = d.createElement('script');
|
|
|
s.src = 'https://nicksxs.disqus.com/count.js';
|
|
|
s.id = 'dsq-count-scr';
|
|
|
(d.head || d.body).appendChild(s);
|
|
|
}
|
|
|
// defer loading until the whole page loading is completed
|
|
|
window.addEventListener('load', loadCount, false);
|
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
</html>
|