<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <author>
    <name>木木</name>
  </author>
  <generator uri="https://hexo.io/">Hexo</generator>
  <id>https://tianwen42.top/</id>
  <link href="https://tianwen42.top/" rel="alternate"/>
  <link href="https://tianwen42.top/atom.xml" rel="self"/>
  <rights>All rights reserved 2026, 木木</rights>
  <subtitle>木木和他的朋友们</subtitle>
  <title>木木和他的朋友们</title>
  <updated>2022-07-07T00:14:06.000Z</updated>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="读书" scheme="https://tianwen42.top/categories/%E8%AF%BB%E4%B9%A6/"/>
    <content>
      <![CDATA[<h1 id="《热爱生命》——汪国真"><a href="#%E3%80%8A%E7%83%AD%E7%88%B1%E7%94%9F%E5%91%BD%E3%80%8B%E2%80%94%E2%80%94%E6%B1%AA%E5%9B%BD%E7%9C%9F" class="headerlink" title="《热爱生命》——汪国真"></a>《热爱生命》——汪国真</h1><blockquote><p>我不去想，<br>是否能够成功 ，<br>既然选择了远方 ，<br>便只顾风雨兼程。<br>我不去想，<br>能否赢得爱情 ，<br>既然钟情于玫瑰 ，<br>就勇敢地吐露真诚 。<br>我不去想，<br>身后会不会袭来寒风冷雨 ，<br>既然目标是地平线，<br>留给世界的只能是背影 。<br>我不去想，<br>未来是平坦还是泥泞 ，<br>只要热爱生命 ，<br>一切，都在意料之中。</p></blockquote>]]>
    </content>
    <id>https://tianwen42.top/posts/fab5.html</id>
    <link href="https://tianwen42.top/posts/fab5.html"/>
    <published>2022-07-06T08:18:00.000Z</published>
    <summary>
      <![CDATA[<h1 id="《热爱生命》——汪国真"><a href="#%E3%80%8A%E7%83%AD%E7%88%B1%E7%94%9F%E5%91%BD%E3%80%8B%E2%80%94%E2%80%94%E6%B1%AA%E5%9B%BD%E7%9C%9F"]]>
    </summary>
    <title>热爱生命</title>
    <updated>2022-07-07T00:14:06.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <content>
      <![CDATA[<h2 id="题目"><a href="#%E9%A2%98%E7%9B%AE" class="headerlink" title="题目"></a>题目</h2><ol start="342"><li>4的幂</li></ol><p>难度：简单</p><p>给定一个整数，写一个函数来判断它是否是 4 的幂次方。如果是，返回 true ；否则，返回 false 。</p><p>整数 n 是 4 的幂次方需满足：存在整数 x 使得 n == 4<sup>x</sup></p><p><strong>示例 1：</strong></p><pre><code class="language-text">输入：n = 16输出：true</code></pre><p><strong>示例 2：</strong></p><pre><code class="language-text">输入：n = 5输出：false</code></pre><p><strong>示例 3：</strong></p><pre><code class="language-text">输入：n = 1输出：true</code></pre><p><strong>提示：</strong></p><ul><li>-2<sup>31</sup> &lt;= n &lt;= 2<sup>31</sup> - 1</li></ul><p><strong>进阶：</strong>你能不使用循环或者递归来完成本题吗？</p><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/power-of-four/">https://leetcode-cn.com/problems/power-of-four/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>4的n次幂模4  和 4的 n-k次幂模4 都为0</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-cpp">/* * @lc app=leetcode.cn id=342 lang=cpp * * [342] 4的幂 */// @lc code=startclass Solution &#123;public:    bool isPowerOfFour(int num) &#123;        return num&gt;0 &amp;&amp; (num == 1 ||(num%4==0 &amp;&amp; isPowerOfFour(num/4)));    &#125;&#125;;// @lc code=end</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/9c17.html</id>
    <link href="https://tianwen42.top/posts/9c17.html"/>
    <published>2022-04-19T14:43:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目"><a href="#%E9%A2%98%E7%9B%AE" class="headerlink" title="题目"></a>题目</h2><ol]]>
    </summary>
    <title>342. 4的幂</title>
    <updated>2022-04-28T13:54:30.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <category term="剑指 Offer" scheme="https://tianwen42.top/tags/%E5%89%91%E6%8C%87-Offer/"/>
    <content>
      <![CDATA[<h2 id="题目-剑指-Offer-II-079-所有子集"><a href="#%E9%A2%98%E7%9B%AE-%E5%89%91%E6%8C%87-Offer-II-079-%E6%89%80%E6%9C%89%E5%AD%90%E9%9B%86" class="headerlink" title="题目.剑指 Offer II 079. 所有子集"></a>题目.剑指 Offer II 079. 所有子集</h2><p>难度：中等</p><p>给定一个整数数组 nums ，数组中的元素 <strong>互不相同</strong> 。返回该数组所有可能的子集（幂集）。</p><p>解集 <strong>不能</strong> 包含重复的子集。你可以按 <strong>任意顺序</strong> 返回解集。</p><p><strong>示例 1：</strong></p><pre><code class="language-text">输入：nums = [1,2,3]输出：[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]</code></pre><p><strong>示例 2：</strong></p><pre><code class="language-text">输入：nums = [0]输出：[[],[0]]</code></pre><p><strong>提示：</strong></p><ul><li>1 &lt;= nums.length &lt;= 10</li><li>-10 &lt;= nums[i] &lt;= 10</li><li>nums 中的所有元素 <strong>互不相同</strong></li></ul><p>注意：本题与主站 78 题相同： <a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/subsets/">https://leetcode-cn.com/problems/subsets/</a></p><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/TVdhkn/">https://leetcode-cn.com/problems/TVdhkn/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>可以正常遍历，也可以用dfs</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-cpp">class Solution &#123;public:    vector&lt;vector&lt;int&gt;&gt; subsets(vector&lt;int&gt;&amp; nums) &#123;        vector&lt;vector&lt;int&gt;&gt; res&#123;vector&lt;int&gt;()&#125;;        int i, j, len;        for (i=0; i&lt;nums.size(); i++) &#123;            len = res.size();            for (j=0; j&lt;len; j++) &#123;                auto tmp = res[j];                tmp.push_back(nums[i]);                res.push_back(tmp);            &#125;        &#125;        return res;    &#125;&#125;;</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/9857.html</id>
    <link href="https://tianwen42.top/posts/9857.html"/>
    <published>2022-04-16T15:44:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目-剑指-Offer-II-079-所有子集"><a href="#%E9%A2%98%E7%9B%AE-%E5%89%91%E6%8C%87-Offer-II-079-%E6%89%80%E6%9C%89%E5%AD%90%E9%9B%86"]]>
    </summary>
    <title>剑指 Offer II 079. 所有子集</title>
    <updated>2022-04-28T13:54:30.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <content>
      <![CDATA[<h2 id="题目22-括号生成"><a href="#%E9%A2%98%E7%9B%AE22-%E6%8B%AC%E5%8F%B7%E7%94%9F%E6%88%90" class="headerlink" title="题目22.括号生成"></a>题目22.括号生成</h2><p>难度：中等</p><p>数字 n 代表生成括号的对数，请你设计一个函数，用于能够生成所有可能的并且 **有效的 **括号组合。</p><p><strong>示例 1：</strong></p><pre><code class="language-text">输入：n = 3输出：[&quot;((()))&quot;,&quot;(()())&quot;,&quot;(())()&quot;,&quot;()(())&quot;,&quot;()()()&quot;]</code></pre><p><strong>示例 2：</strong></p><pre><code class="language-text">输入：n = 1输出：[&quot;()&quot;]</code></pre><p><strong>提示：</strong></p><ul><li>1 &lt;= n &lt;= 8</li></ul><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/generate-parentheses/">https://leetcode-cn.com/problems/generate-parentheses/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>dfs，左右子树为（），刚好对应二叉树结构</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-cpp">class Solution &#123;public:    vector&lt;string&gt; generateParenthesis(int n) &#123;        vector&lt;string&gt; res;        if (n &lt;= 0) return res;        dfs(n, &quot;&quot;, res, 0, 0);        return res;    &#125;    void dfs(int n, string path, vector&lt;string&gt;&amp; res, int open, int close) &#123;        if (open &gt; n || close &gt; open) return;        if (path.length() == 2 * n) &#123;            res.push_back(path);            return;        &#125;        dfs(n, path + &quot;(&quot;, res, open + 1, close);        dfs(n, path + &quot;)&quot;, res, open, close + 1);    &#125;&#125;;</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/59d6.html</id>
    <link href="https://tianwen42.top/posts/59d6.html"/>
    <published>2022-04-14T13:38:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目22-括号生成"><a href="#%E9%A2%98%E7%9B%AE22-%E6%8B%AC%E5%8F%B7%E7%94%9F%E6%88%90" class="headerlink"]]>
    </summary>
    <title>22. 括号生成</title>
    <updated>2022-04-14T13:51:28.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <category term="二分法" scheme="https://tianwen42.top/tags/%E4%BA%8C%E5%88%86%E6%B3%95/"/>
    <content>
      <![CDATA[<h2 id="题目35-搜索插入位置"><a href="#%E9%A2%98%E7%9B%AE35-%E6%90%9C%E7%B4%A2%E6%8F%92%E5%85%A5%E4%BD%8D%E7%BD%AE" class="headerlink" title="题目35.搜索插入位置"></a>题目35.搜索插入位置</h2><p>难度：简单</p><p>给定一个排序数组和一个目标值，在数组中找到目标值，并返回其索引。如果目标值不存在于数组中，返回它将会被按顺序插入的位置。</p><p>请必须使用时间复杂度为 O(log n) 的算法。</p><p><strong>示例 1:</strong></p><pre><code class="language-text">输入: nums = [1,3,5,6], target = 5输出: 2</code></pre><p><strong>示例 2:</strong></p><pre><code class="language-text">输入: nums = [1,3,5,6], target = 2输出: 1</code></pre><p><strong>示例 3:</strong></p><pre><code class="language-text">输入: nums = [1,3,5,6], target = 7输出: 4</code></pre><p><strong>提示:</strong></p><ul><li>1 &lt;= nums.length &lt;= 10<sup>4</sup></li><li>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></li><li>nums 为 **无重复元素 **的 **升序 **排列数组</li><li>-10<sup>4</sup> &lt;= target &lt;= 10<sup>4</sup></li></ul><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/search-insert-position/">https://leetcode-cn.com/problems/search-insert-position/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>简单二分，要求O(log n) ，尽量不要暴力搜索</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-cpp">class Solution &#123;public:    int searchInsert(vector&lt;int&gt;&amp; nums, int target) &#123;        int left=0;        int right=nums.size()-1;        int mid=left+(right-left)/2;        if(target&gt;nums[right])&#123;            return right+1;        &#125;        while(left&lt;right)&#123;            if(nums[mid]==target)&#123;                return mid;            &#125;            if(nums[mid]&lt;target)&#123;                left=mid+1;            &#125;else&#123;                right=mid;            &#125;            mid=left+(right-left)/2;        &#125;        return mid;    &#125;&#125;;</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/9b97.html</id>
    <link href="https://tianwen42.top/posts/9b97.html"/>
    <published>2022-04-13T06:21:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目35-搜索插入位置"><a href="#%E9%A2%98%E7%9B%AE35-%E6%90%9C%E7%B4%A2%E6%8F%92%E5%85%A5%E4%BD%8D%E7%BD%AE" class="headerlink"]]>
    </summary>
    <title>35. 搜索插入位置</title>
    <updated>2022-04-13T10:23:24.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <category term="接雨水" scheme="https://tianwen42.top/tags/%E6%8E%A5%E9%9B%A8%E6%B0%B4/"/>
    <content>
      <![CDATA[<h2 id="题目42-接雨水"><a href="#%E9%A2%98%E7%9B%AE42-%E6%8E%A5%E9%9B%A8%E6%B0%B4" class="headerlink" title="题目42.接雨水"></a>题目42.接雨水</h2><p>难度：困难</p><p>给定 n 个非负整数表示每个宽度为 1 的柱子的高度图，计算按此排列的柱子，下雨之后能接多少雨水。</p><p><strong>示例 1：</strong></p><img style="height: 161px; width: 412px;" src="https://qiniu.tianwen42.top/picgo/rainwatertrap.png"><pre><code class="language-text">输入：height = [0,1,0,2,1,0,1,3,2,1,2,1]输出：6解释：上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图，在这种情况下，可以接 6 个单位的雨水（蓝色部分表示雨水）。 </code></pre><p><strong>示例 2：</strong></p><pre><code class="language-text">输入：height = [4,2,0,3,2,5]输出：9</code></pre><p><strong>提示：</strong></p><ul><li>n == height.length</li><li>1 &lt;= n &lt;= 2 * 10<sup>4</sup></li><li>0 &lt;= height[i] &lt;= 10<sup>5</sup></li></ul><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/trapping-rain-water/">https://leetcode-cn.com/problems/trapping-rain-water/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>日常接雨水，暴力搜索，脑子不够</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><h3 id="暴力搜索"><a href="#%E6%9A%B4%E5%8A%9B%E6%90%9C%E7%B4%A2" class="headerlink" title="暴力搜索"></a>暴力搜索</h3><pre><code class="language-cpp">class Solution &#123;public:    int trap(vector&lt;int&gt;&amp; nums) &#123;        int maxHeight=0;                int rain=0;        for(int i=0;i&lt;nums.size();i++)&#123;            maxHeight=max(nums[i],maxHeight);        &#125;        for(int i=0;i&lt;nums.size();i++)&#123;            int maxleft=0,maxright=0;            //左侧最大高度            for(int j=0;j&lt;=i;j++)&#123;                maxleft=max(maxleft,nums[j]);            &#125;            // 右侧最大高度            for(int j=i;j&lt;nums.size();j++)&#123;                maxright=max(maxright,nums[j]);            &#125;            //当前位置可接高度min(Maxleft,Maxright),取决于左右最大高度低值            rain+=min(maxright, maxleft)-nums[i];;        &#125;        return rain;    &#125;&#125;;</code></pre><blockquote><p>超时了！！！×&amp;%￥#@……。</p><p>果然日常接雨水啊！！！！！</p></blockquote><h3 id="DP法"><a href="#DP%E6%B3%95" class="headerlink" title="DP法"></a>DP法</h3><blockquote><p>看看别人的，需要从两头重新遍历一遍求出左右两侧的最大高度，这里是有很多重复计算的，很明显最大高度是可以记忆化的，用两个数组分别存每个位置的左右最大高度，</p><p>int[][] dp = new int [n] [2],其中，dp [i] [0] 表示下标i的柱子左边的最大值，dp[i] [1] 表示下标i的柱子右边的最大值。</p><p>类比这题</p><ul><li><a target="_blank" rel="noopener" href="https://tianwen42.top/posts/ea37.html">807.城市天际线</a></li></ul></blockquote><p>左右高度数组如下图所示</p><p><img src="https://qiniu.tianwen42.top/picgo/rain0421.jpg" alt="img"></p><pre><code class="language-cpp">class Solution &#123;public:int trap(vector&lt;int&gt;&amp; height) &#123;int n = height.size();// left[i]表示i左边的最大值，right[i]表示i右边的最大值vector&lt;int&gt; left(n), right(n);for (int i = 1; i &lt; n; i++) &#123;left[i] = max(left[i - 1], height[i - 1]);&#125;for (int i = n - 2; i &gt;= 0; i--) &#123;right[i] = max(right[i + 1], height[i + 1]);&#125;int water = 0;for (int i = 0; i &lt; n; i++) &#123;int level = min(left[i], right[i]);water += max(0, level - height[i]);&#125;return water;&#125;&#125;;</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/5a16.html</id>
    <link href="https://tianwen42.top/posts/5a16.html"/>
    <published>2022-04-11T06:11:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目42-接雨水"><a href="#%E9%A2%98%E7%9B%AE42-%E6%8E%A5%E9%9B%A8%E6%B0%B4" class="headerlink"]]>
    </summary>
    <title>42. 接雨水</title>
    <updated>2022-04-13T10:25:32.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <content>
      <![CDATA[<h2 id="题目852-山脉数组的峰顶索引"><a href="#%E9%A2%98%E7%9B%AE852-%E5%B1%B1%E8%84%89%E6%95%B0%E7%BB%84%E7%9A%84%E5%B3%B0%E9%A1%B6%E7%B4%A2%E5%BC%95" class="headerlink" title="题目852.山脉数组的峰顶索引"></a>题目852.山脉数组的峰顶索引</h2><p>难度：简单</p><p><strong>山脉数组</strong><code>arr</code></p><ul><li>arr.length &gt;= 3</li><li>存在 i（0 &lt; i &lt; arr.length - 1）使得：  <ul>      <li>arr[0] &lt; arr[1] &lt; ... arr[i-1] &lt; arr[i] </li>      <li>arr[i] &gt; arr[i+1] &gt; ... &gt; arr[arr.length - 1]</li>  </ul></li></ul><p>给你由整数组成的山脉数组 arr ，返回任何满足 arr[0] &lt; arr[1] &lt; … arr[i - 1] &lt; arr[i] &gt; arr[i + 1] &gt; … &gt; arr[arr.length - 1] 的下标 i 。</p><p><strong>示例 1：</strong></p><pre><code class="language-text">输入：arr = [0,1,0]输出：1</code></pre><p><strong>示例 2：</strong></p><pre><code class="language-text">输入：arr = [0,2,1,0]输出：1</code></pre><p><strong>示例 3：</strong></p><pre><code class="language-text">输入：arr = [0,10,5,2]输出：1</code></pre><p><strong>示例 4：</strong></p><pre><code class="language-text">输入：arr = [3,4,5,1]输出：2</code></pre><p><strong>示例 5：</strong></p><pre><code class="language-text">输入：arr = [24,69,100,99,79,78,67,36,26,19]输出：2</code></pre><p><strong>提示：</strong></p><ul><li>3 &lt;= arr.length &lt;= 10<sup>4</sup></li><li>0 &lt;= arr[i] &lt;= 10<sup>6</sup></li><li>题目数据保证 arr 是一个山脉数组</li></ul><p><strong>进阶：</strong>很容易想到时间复杂度 O(n) 的解决方案，你可以设计一个 O(log(n)) 的解决方案吗？</p><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/peak-index-in-a-mountain-array/">https://leetcode-cn.com/problems/peak-index-in-a-mountain-array/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><ol><li>直接暴力法arr[i]&gt;arr[i-1]&amp;&amp;arr[i]&gt;arr[i+1]</li><li>二分法</li></ol><p>支持暴力法和二分法，显然二分法更快</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-cpp">//暴力法class Solution &#123;public:    int peakIndexInMountainArray(vector&lt;int&gt;&amp; arr) &#123;        if(arr[0]&gt;arr[1])&#123;            return 0;        &#125;        for(int i=1;i&lt;arr.size()-1;i++)&#123;            if(arr[i]&gt;arr[i-1]&amp;&amp;arr[i]&gt;arr[i+1])&#123;                return i;            &#125;         &#125;        return arr.size()-1;    &#125;&#125;;</code></pre><pre><code class="language-cpp">class Solution &#123;public:    int peakIndexInMountainArray(vector&lt;int&gt;&amp; arr) &#123;        // if(arr[0]&gt;arr[1])&#123;return 0;&#125;        int left=0,right=arr.size()-1,mid=left+(right-left)/2;        while(left!=right)&#123;            if(arr[left]&lt;arr[mid])&#123;                right=mid;            &#125;else&#123;                left=mid+1;            &#125;            mid=left+(right-left)/2;        &#125;        return left;    &#125;&#125;;</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/7bb.html</id>
    <link href="https://tianwen42.top/posts/7bb.html"/>
    <published>2022-04-10T15:53:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目852-山脉数组的峰顶索引"><a href="#%E9%A2%98%E7%9B%AE852-%E5%B1%B1%E8%84%89%E6%95%B0%E7%BB%84%E7%9A%84%E5%B3%B0%E9%A1%B6%E7%B4%A2%E5%BC%95"]]>
    </summary>
    <title>852. 山脉数组的峰顶索引</title>
    <updated>2022-04-13T10:23:24.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <category term="二分查找" scheme="https://tianwen42.top/tags/%E4%BA%8C%E5%88%86%E6%9F%A5%E6%89%BE/"/>
    <category term="核心" scheme="https://tianwen42.top/tags/%E6%A0%B8%E5%BF%83/"/>
    <content>
      <![CDATA[<h2 id="题目374-猜数字大小"><a href="#%E9%A2%98%E7%9B%AE374-%E7%8C%9C%E6%95%B0%E5%AD%97%E5%A4%A7%E5%B0%8F" class="headerlink" title="题目374.猜数字大小"></a>题目374.猜数字大小</h2><p>难度：简单</p><p>猜数字游戏的规则如下：</p><ul><li>每轮游戏，我都会从 <strong>1</strong> 到 <em><strong>n</strong></em> 随机选择一个数字。 请你猜选出的是哪个数字。</li><li>如果你猜错了，我会告诉你，你猜测的数字比我选出的数字是大了还是小了。</li></ul><p>你可以通过调用一个预先定义好的接口 int guess(int num) 来获取猜测结果，返回值一共有 3 种可能的情况（-1，1 或 0）：</p><ul><li>-1：我选出的数字比你猜的数字小 pick &lt; num</li><li>1：我选出的数字比你猜的数字大 pick &gt; num</li><li>0：我选出的数字和你猜的数字一样。恭喜！你猜对了！pick == num</li></ul><p>返回我选出的数字。</p><p><strong>示例 1：</strong></p><pre><code class="language-text">输入：n = 10, pick = 6输出：6</code></pre><p><strong>示例 2：</strong></p><pre><code class="language-text">输入：n = 1, pick = 1输出：1</code></pre><p><strong>示例 3：</strong></p><pre><code class="language-text">输入：n = 2, pick = 1输出：1</code></pre><p><strong>示例 4：</strong></p><pre><code class="language-text">输入：n = 2, pick = 2输出：2</code></pre><p><strong>提示：</strong></p><ul><li>1 &lt;= n &lt;= 2<sup>31</sup> - 1</li><li>1 &lt;= pick &lt;= n</li></ul><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/guess-number-higher-or-lower/">https://leetcode-cn.com/problems/guess-number-higher-or-lower/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p><strong>二分核心</strong>，精髓，这样写防止越界，mid = left + ((right - left) / 2);</p><pre><code class="language-java">while(l!=r)&#123;    int mid = l +(r - l)/2;    if(guess(mid)==1) l = mid+1;    else r = mid;&#125;</code></pre></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-java">public class Solution extends GuessGame &#123;    public int guessNumber(int n) &#123;        int l = 1, r = n;        while(l!=r)&#123;            int mid = l +(r - l)/2;            if(guess(mid)==1) l = mid+1;            else r = mid;        &#125;        return l;    &#125;&#125;</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/b877.html</id>
    <link href="https://tianwen42.top/posts/b877.html"/>
    <published>2022-04-10T15:40:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目374-猜数字大小"><a href="#%E9%A2%98%E7%9B%AE374-%E7%8C%9C%E6%95%B0%E5%AD%97%E5%A4%A7%E5%B0%8F" class="headerlink"]]>
    </summary>
    <title>374. 猜数字大小</title>
    <updated>2022-04-13T10:23:24.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <content>
      <![CDATA[<h2 id="题目807-保持城市天际线"><a href="#%E9%A2%98%E7%9B%AE807-%E4%BF%9D%E6%8C%81%E5%9F%8E%E5%B8%82%E5%A4%A9%E9%99%85%E7%BA%BF" class="headerlink" title="题目807.保持城市天际线"></a>题目807.保持城市天际线</h2><p>难度：中等</p><p>给你一座由 n x n 个街区组成的城市，每个街区都包含一座立方体建筑。给你一个下标从 <strong>0</strong> 开始的 n x n 整数矩阵 grid ，其中 grid[r][c] 表示坐落于 r 行 c 列的建筑物的 <strong>高度</strong> 。</p><p>城市的 <strong>天际线</strong> 是从远处观察城市时，所有建筑物形成的外部轮廓。从东、南、西、北四个主要方向观测到的 <strong>天际线</strong> 可能不同。</p><p>我们被允许为 <strong>任意数量的建筑物 <strong>的高度增加</strong> 任意增量（不同建筑物的增量可能不同）</strong> 。 高度为 0 的建筑物的高度也可以增加。然而，增加的建筑物高度 <strong>不能影响</strong> 从任何主要方向观察城市得到的 <strong>天际线</strong> 。</p><p>在 <strong>不改变</strong> 从任何主要方向观测到的城市 <strong>天际线</strong> 的前提下，返回建筑物可以增加的 <strong>最大高度增量总和</strong> 。</p><p><strong>示例 1：</strong></p><img style="width: 700px; height: 603px;" src="https://qiniu.tianwen42.top/picgo/807-ex1.png" alt=""><pre><code class="language-text">输入：grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]输出：35解释：建筑物的高度如上图中心所示。用红色绘制从不同方向观看得到的天际线。在不影响天际线的情况下，增加建筑物的高度：gridNew = [ [8, 4, 8, 7],            [7, 4, 7, 7],            [9, 4, 8, 7],            [3, 3, 3, 3] ]</code></pre><p><strong>示例 2：</strong></p><pre><code class="language-text">输入：grid = [[0,0,0],[0,0,0],[0,0,0]]输出：0解释：增加任何建筑物的高度都会导致天际线的变化。</code></pre><p><strong>提示：</strong></p><ul><li>n == grid.length</li><li>n == grid[r].length</li><li>2 &lt;= n &lt;= 50</li><li>0 &lt;= grid[r][c] &lt;= 100</li></ul><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/">https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>正视（先列中最大）和侧视（先行中最大）的最大值，再求n*n根据两个组的最小数赋值给[i,j]，即为当前的楼最低点，算与真实的差值即为加高层数</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-cpp">class Solution &#123;public:    int maxIncreaseKeepingSkyline(vector&lt;vector&lt;int&gt;&gt;&amp; grid) &#123;        int n=grid.size();        //侧视图天际线最低        vector&lt;int&gt; row_max_min(n);        //正视图天际线最低        vector&lt;int&gt; col_max_min(n);        for(int i=0;i&lt;n;i++)&#123;            int tmp=*max_element(grid[i].begin(),grid[i].end());            row_max_min[i]=tmp;        &#125;        for(int i = 0; i &lt; n; i++)        &#123;            for(int j = 0; j &lt; n; j++)            &#123;                col_max_min[j] = max(col_max_min[j], grid[i][j]);            &#125;        &#125;        int res = 0;        for(int i = 0; i &lt; n; i++)        &#123;            for(int j = 0; j &lt; n; j++)            &#123;                res += min(col_max_min[j],row_max_min[i])-grid[i][j];            &#125;        &#125;        return res;    &#125;&#125;;</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/ea37.html</id>
    <link href="https://tianwen42.top/posts/ea37.html"/>
    <published>2022-04-06T15:58:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目807-保持城市天际线"><a href="#%E9%A2%98%E7%9B%AE807-%E4%BF%9D%E6%8C%81%E5%9F%8E%E5%B8%82%E5%A4%A9%E9%99%85%E7%BA%BF" class="headerlink"]]>
    </summary>
    <title>807. 保持城市天际线</title>
    <updated>2022-04-11T06:14:14.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <content>
      <![CDATA[<h2 id="题目704-二分查找"><a href="#%E9%A2%98%E7%9B%AE704-%E4%BA%8C%E5%88%86%E6%9F%A5%E6%89%BE" class="headerlink" title="题目704.二分查找"></a>题目704.二分查找</h2><p>难度：简单</p><p>给定一个 n 个元素有序的（升序）整型数组 nums 和一个目标值 target  ，写一个函数搜索 nums 中的 target，如果目标值存在返回下标，否则返回 -1。</p><br>**示例 1:**<pre><code class="language-text">输入: nums = [-1,0,3,5,9,12], target = 9输出: 4解释: 9 出现在 nums 中并且下标为 4</code></pre><p><strong>示例 2:</strong></p><pre><code class="language-text">输入: nums = [-1,0,3,5,9,12], target = 2输出: -1解释: 2 不存在 nums 中因此返回 -1</code></pre><p><strong>提示：</strong></p><ol><li>你可以假设 nums 中的所有元素是不重复的。</li><li>n 将在 [1, 10000]之间。</li><li>nums 的每个元素都将在 [-9999, 9999]之间。</li></ol><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/binary-search/">https://leetcode-cn.com/problems/binary-search/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>两种方法，注意边界条件和更新条件</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-cpp">class Solution &#123;public:    // 定义target在左闭右开的区间里，即：[left, right]    int search(vector&lt;int&gt; &amp;nums, int target) &#123;        int head = 0;        int rear = nums.size() - 1;        int mid;        while (head &lt;= rear) &#123;            mid = (head + rear) / 2;            if (nums[mid] == target)                return mid;            else if (nums[mid] &lt; target) &#123;                head = mid + 1; // 注意            &#125; else if (nums[mid] &gt; target) &#123;                rear = mid - 1;            &#125;        &#125;        return 0;    &#125;    // 定义target在左闭右开的区间里，即：[left, right)    int search2(vector&lt;int&gt;&amp; nums, int target) &#123;        int left = 0;        int right = nums.size(); // 定义target在左闭右开的区间里，即：[left, right)        while (left &lt; right) &#123; // 因为left == right的时候，在[left, right)是无效的空间，所以使用 &lt;            int middle = left + ((right - left) &gt;&gt; 1);            if (nums[middle] &gt; target) &#123;                right = middle; // target 在左区间，在[left, middle)中            &#125; else if (nums[middle] &lt; target) &#123;                left = middle + 1; // target 在右区间，在[middle + 1, right)中            &#125; else &#123; // nums[middle] == target                return middle; // 数组中找到目标值，直接返回下标            &#125;        &#125;        // 未找到目标值        return -1;    &#125;&#125;;</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/fe37.html</id>
    <link href="https://tianwen42.top/posts/fe37.html"/>
    <published>2022-03-27T12:25:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目704-二分查找"><a href="#%E9%A2%98%E7%9B%AE704-%E4%BA%8C%E5%88%86%E6%9F%A5%E6%89%BE" class="headerlink"]]>
    </summary>
    <title>704. 二分查找</title>
    <updated>2022-04-11T06:14:14.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <content>
      <![CDATA[<h2 id="题目"><a href="#%E9%A2%98%E7%9B%AE" class="headerlink" title="题目"></a>题目</h2><ol start="217"><li>存在重复元素</li></ol><p>难度：简单</p><p><code>nums</code></p><p><strong>至少两次</strong></p><p><code>true</code></p><p><code>false</code></p><p><strong>示例 1：</strong></p><pre><code class="language-text">输入：nums = [1,2,3,1]输出：true</code></pre><p><strong>示例 2：</strong></p><pre><code class="language-text">输入：nums = [1,2,3,4]输出：false</code></pre><p><strong>示例 3：</strong></p><pre><code class="language-text">输入：nums = [1,1,1,3,3,4,3,2,4,2]输出：true</code></pre><p><strong>提示：</strong></p><ul><li>1 &lt;= nums.length &lt;= 10<sup>5</sup></li><li>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></li></ul><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/contains-duplicate/">https://leetcode-cn.com/problems/contains-duplicate/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>排序，有相同的肯定近邻</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-cpp">class Solution &#123;public:    bool containsDuplicate(vector&lt;int&gt;&amp; nums) &#123;        sort(nums.begin(), nums.end());        while(nums.size()&gt;1&amp;&amp;(nums[nums.size()-1]!=nums[nums.size()-2]))&#123;            // 判断栈顶和倒二是否相等，注意边界条件            nums.pop_back();        &#125;        // for(int i=0; i&lt;nums.size();i++)&#123;        //     cout &lt;&lt; nums[i] &lt;&lt; &quot; &quot;;        // &#125;        if(nums.size()==1) return false;else return true;    &#125;&#125;;</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/3fb6.html</id>
    <link href="https://tianwen42.top/posts/3fb6.html"/>
    <published>2022-03-25T13:02:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目"><a href="#%E9%A2%98%E7%9B%AE" class="headerlink" title="题目"></a>题目</h2><ol]]>
    </summary>
    <title>217. 存在重复元素</title>
    <updated>2022-04-11T06:14:14.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="生活" scheme="https://tianwen42.top/categories/%E7%94%9F%E6%B4%BB/"/>
    <category term="归档" scheme="https://tianwen42.top/tags/%E5%BD%92%E6%A1%A3/"/>
    <content>
      <![CDATA[<p>堆了个奇怪的雪人</p><p><img src="http://qiniu.tianwen42.top/picgo/IMG_20201229_200725.jpg" alt="IMG_20201229_200725"></p><p>秦淮河畔</p><p><img src="http://qiniu.tianwen42.top/picgo/IMG_20210429_191925.jpg" alt="IMG_20210429_191925"></p><p><img src="http://qiniu.tianwen42.top/picgo/IMG_20211017_113126.jpg" alt="IMG_20211017_113126"></p><p><img src="http://qiniu.tianwen42.top/picgo/0009.jpg" alt="0009"><img src="http://qiniu.tianwen42.top/picgo/%5BThumb%5D640326600415-3ec0b87c-0587-317d-862b-68d4c1744c4f.jpg" alt="[Thumb]640326600415-3ec0b87c-0587-317d-862b-68d4c1744c4f"></p><img src="http://qiniu.tianwen42.top/picgo/mmexport1641051034837.jpg" alt="mmexport1641051034837" style="zoom:50%;"><p><img src="http://qiniu.tianwen42.top/picgo/mmexport1642862346561.jpg" alt="mmexport1642862346561"><img src="http://qiniu.tianwen42.top/picgo/mmexport1640590404629.jpg" alt="mmexport1640590404629"></p><p><img src="http://qiniu.tianwen42.top/picgo/IMG_20220125_130126.jpg" alt="IMG_20220125_130126"></p><p>分割线，听首歌吧</p><iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="530" height="86" src="//music.163.com/outchain/player?type=2&amp;id=26494698&amp;auto=0&amp;height=66"></iframe>]]>
    </content>
    <id>https://tianwen42.top/posts/b2d9.html</id>
    <link href="https://tianwen42.top/posts/b2d9.html"/>
    <published>2022-03-21T03:04:00.000Z</published>
    <summary>
      <![CDATA[<p>堆了个奇怪的雪人</p>
<p><img src="http://qiniu.tianwen42.top/picgo/IMG_20201229_200725.jpg" alt="IMG_20201229_200725"></p>
<p>秦淮河畔</p>
<p><img]]>
    </summary>
    <title>2021归档</title>
    <updated>2022-06-30T08:02:52.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <category term="dp" scheme="https://tianwen42.top/tags/dp/"/>
    <content>
      <![CDATA[<h2 id="题目343-整数拆分"><a href="#%E9%A2%98%E7%9B%AE343-%E6%95%B4%E6%95%B0%E6%8B%86%E5%88%86" class="headerlink" title="题目343. 整数拆分"></a>题目343. 整数拆分</h2><p>难度：中等</p><p>给定一个正整数 n ，将其拆分为 k 个 <strong>正整数</strong> 的和（ k &gt;= 2 ），并使这些整数的乘积最大化。</p><p>返回 <em>你可以获得的最大乘积</em> 。</p><p><strong>示例 1:</strong></p><pre><code class="language-text">输入: n = 2输出: 1解释: 2 = 1 + 1, 1 × 1 = 1。</code></pre><p><strong>示例 2:</strong></p><pre><code class="language-text">输入: n = 10输出: 36解释: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36。</code></pre><p><strong>提示:</strong></p><ul><li>2 &lt;= n &lt;= 58</li></ul><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/integer-break/">https://leetcode-cn.com/problems/integer-break/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>dp题目</p><p>dp[i] = max(dp[i], max((i - j) * j, dp[i - j] * j));</p><p>dp[i] 是依靠 dp[i - j]的状态，所以遍历i一定是从前向后遍历，先有dp[i - j]再有dp[i]</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-cpp">//动态规划class Solution &#123;public:    int integerBreak(int n) &#123;        if(n==2)            return 1;        vector&lt;int&gt; dp(n+1,0);        dp[2] = 1;        for(int i=3;i&lt;=n;++i)&#123;            for(int j=1;j&lt;i;++j)                dp[i] = max(dp[i],max(dp[i-j]*j,(i-j)*j));        &#125;        return dp[n];    &#125;&#125;;</code></pre><pre><code class="language-cpp">//贪心算法//时间复杂度O(n)//空间复杂度O(1)class Solution &#123;public:    int integerBreak(int n) &#123;        if (n == 2) return 1;        if (n == 3) return 2;        if (n == 4) return 4;        int result = 1;        while (n &gt; 4) &#123;            result *= 3;            n -= 3;        &#125;        result *= n;        return result;    &#125;&#125;;</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/5d37.html</id>
    <link href="https://tianwen42.top/posts/5d37.html"/>
    <published>2022-03-03T08:02:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目343-整数拆分"><a href="#%E9%A2%98%E7%9B%AE343-%E6%95%B4%E6%95%B0%E6%8B%86%E5%88%86" class="headerlink" title="题目343. 整数拆分"></a>题目343.]]>
    </summary>
    <title>343. 整数拆分</title>
    <updated>2022-04-11T06:14:14.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <category term="数字切片" scheme="https://tianwen42.top/tags/%E6%95%B0%E5%AD%97%E5%88%87%E7%89%87/"/>
    <content>
      <![CDATA[<h2 id="题目7-整数反转"><a href="#%E9%A2%98%E7%9B%AE7-%E6%95%B4%E6%95%B0%E5%8F%8D%E8%BD%AC" class="headerlink" title="题目7.整数反转"></a>题目7.整数反转</h2><p>难度：中等</p><p>给你一个 32 位的有符号整数 x ，返回将 x 中的数字部分反转后的结果。</p><p>如果反转后整数超过 32 位的有符号整数的范围 [−2<sup>31</sup>,  2<sup>31 </sup>− 1] ，就返回 0。</p><p><strong>假设环境不允许存储 64 位整数（有符号或无符号）。</strong></p><p><strong>示例 1：</strong></p><pre><code class="language-text">输入：x = 123输出：321</code></pre><p><strong>示例 2：</strong></p><pre><code class="language-text">输入：x = -123输出：-321</code></pre><p><strong>示例 3：</strong></p><pre><code class="language-text">输入：x = 120输出：21</code></pre><p><strong>示例 4：</strong></p><pre><code class="language-text">输入：x = 0输出：0</code></pre><p><strong>提示：</strong></p><ul><li>-2<sup>31</sup> &lt;= x &lt;= 2<sup>31</sup> - 1</li></ul><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/reverse-integer/">https://leetcode-cn.com/problems/reverse-integer/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>整数翻转，123 –&gt; 3 * 10+2 –&gt; 32 * 10+1 –&gt;321</p><p>想到另一个整数拼接的思路 123 –&gt; 123 * 10+1 –&gt; 1231 * 10 +2 –&gt; 12312 * 10 +3 –&gt;123123</p><p>再一个就是整数对称的思路 123 –&gt; 123 * 10+3 –&gt; 1231 * 10 +2 –&gt; 12312 * 10 +1 –&gt;123321</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-cpp">//123  321//-123 -321//0    0#include &lt;iostream&gt;class Solution &#123;public:    int reverse2(int x) &#123;        int ans = 0;        while(x != 0)        &#123;            if(ans &gt; INT_MAX || ans &lt; INT_MIN)                return 0;            ans = ans * 10 + x % 10;            x /= 10;        &#125;        return ans;    &#125;&#125;;</code></pre><pre><code class="language-cpp">//数字对称//123 123321//-8 -88//-10 -1001int symmetryReverse(int x) &#123;        using namespace std;        int ans = x;        while(x != 0)        &#123;            if(ans &gt; INT_MAX || ans &lt; INT_MIN)                return 0;            ans = ans * 10 + x % 10;            //cout&lt;&lt;ans&lt;&lt;endl;            x /= 10;        &#125;        return ans;    &#125;</code></pre><pre><code class="language-cpp">//数字重复//105 105105//10  1010//1   11int digitalRepeated(int x) &#123;        using namespace std;                int ans = x;        int num = 1 + log10(x);  //位数        for (int i = num - 1; i &gt;= 0; i--) &#123;            if (ans == 0 || ans &gt; INT_MAX || ans &lt; INT_MIN)      //用for要注意0或者溢出                return 0;            int maxdigit = (int) pow(10, i);            // cout&lt;&lt;ans&lt;&lt;endl;            ans = ans * 10 + (x / maxdigit) % 10;            x %= maxdigit;        &#125;        return ans;    &#125;</code></pre><blockquote><p>由这一题抽象出对数字的常规算法，详情见<a href="">数字切片</a></p></blockquote>]]>
    </content>
    <id>https://tianwen42.top/posts/676.html</id>
    <link href="https://tianwen42.top/posts/676.html"/>
    <published>2022-02-28T01:16:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目7-整数反转"><a href="#%E9%A2%98%E7%9B%AE7-%E6%95%B4%E6%95%B0%E5%8F%8D%E8%BD%AC" class="headerlink"]]>
    </summary>
    <title>7. 整数反转</title>
    <updated>2022-04-11T06:14:14.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="算法" scheme="https://tianwen42.top/tags/%E7%AE%97%E6%B3%95/"/>
    <category term="leetcode" scheme="https://tianwen42.top/tags/leetcode/"/>
    <category term="字符串" scheme="https://tianwen42.top/tags/%E5%AD%97%E7%AC%A6%E4%B8%B2/"/>
    <category term="贪心算法" scheme="https://tianwen42.top/tags/%E8%B4%AA%E5%BF%83%E7%AE%97%E6%B3%95/"/>
    <content>
      <![CDATA[<h2 id="题目1221-分割平衡字符串"><a href="#%E9%A2%98%E7%9B%AE1221-%E5%88%86%E5%89%B2%E5%B9%B3%E8%A1%A1%E5%AD%97%E7%AC%A6%E4%B8%B2" class="headerlink" title="题目1221.分割平衡字符串"></a>题目1221.分割平衡字符串</h2><p>难度：简单</p><p>在一个 <strong>平衡字符串</strong> 中，’L’ 和 ‘R’ 字符的数量是相同的。</p><p>给你一个平衡字符串 s，请你将它分割成尽可能多的平衡字符串。</p><p><strong>注意：</strong>分割得到的每个字符串都必须是平衡字符串，且分割得到的平衡字符串是原平衡字符串的连续子串。</p><p>返回可以通过分割得到的平衡字符串的 <strong>最大数量</strong> <strong>。</strong></p><p><strong>示例 1：</strong></p><pre><code class="language-text">输入：s = &quot;RLRRLLRLRL&quot;输出：4解释：s 可以分割为 &quot;RL&quot;、&quot;RRLL&quot;、&quot;RL&quot;、&quot;RL&quot; ，每个子字符串中都包含相同数量的 &#39;L&#39; 和 &#39;R&#39; 。</code></pre><p><strong>示例 2：</strong></p><pre><code class="language-text">输入：s = &quot;RLLLLRRRLR&quot;输出：3解释：s 可以分割为 &quot;RL&quot;、&quot;LLLRRR&quot;、&quot;LR&quot; ，每个子字符串中都包含相同数量的 &#39;L&#39; 和 &#39;R&#39; 。</code></pre><p><strong>示例 3：</strong></p><pre><code class="language-text">输入：s = &quot;LLLLRRRR&quot;输出：1解释：s 只能保持原样 &quot;LLLLRRRR&quot;.</code></pre><p><strong>示例 4：</strong></p><pre><code class="language-text">输入：s = &quot;RLRRRLLRLL&quot;输出：2解释：s 可以分割为 &quot;RL&quot;、&quot;RRRLLRLL&quot; ，每个子字符串中都包含相同数量的 &#39;L&#39; 和 &#39;R&#39; 。</code></pre><p><strong>提示：</strong></p><ul><li>1 &lt;= s.length &lt;= 1000</li><li>s[i] = ‘L’ 或 ‘R’</li><li>s 是一个 <strong>平衡</strong> 字符串</li></ul><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/">https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>上楼梯问题，L下一步R上一步，在平地上num+1</p><p>“括号匹配”问题,主要是栈操作,’R’进栈,’L’出栈,栈空则匹配成功,结果加一</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-python">class Solution:    def balancedStringSplit(self, s: str) -&gt; int:        s=list(s)        stack=[]        high,num=0,0        while s:            if s.pop()!=&#39;R&#39;:                high-=1            else:                high+=1            if high==0:                num+=1        return num</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/236.html</id>
    <link href="https://tianwen42.top/posts/236.html"/>
    <published>2022-02-26T16:15:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目1221-分割平衡字符串"><a href="#%E9%A2%98%E7%9B%AE1221-%E5%88%86%E5%89%B2%E5%B9%B3%E8%A1%A1%E5%AD%97%E7%AC%A6%E4%B8%B2"]]>
    </summary>
    <title>1221. 分割平衡字符串</title>
    <updated>2022-04-11T06:14:14.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <content>
      <![CDATA[<h2 id="题目917-仅仅反转字母"><a href="#%E9%A2%98%E7%9B%AE917-%E4%BB%85%E4%BB%85%E5%8F%8D%E8%BD%AC%E5%AD%97%E6%AF%8D" class="headerlink" title="题目917.仅仅反转字母"></a>题目917.仅仅反转字母</h2><p>难度：简单</p><p>给你一个字符串 s ，根据下述规则反转字符串：</p><ul><li>所有非英文字母保留在原有位置。</li><li>所有英文字母（小写或大写）位置反转。</li></ul><p>返回反转后的 s<em> 。</em></p><p><strong>示例 1：</strong></p><pre><code class="language-text">输入：s = &quot;ab-cd&quot;输出：&quot;dc-ba&quot;</code></pre><p><strong>示例 2：</strong></p><pre><code class="language-text">输入：s = &quot;a-bC-dEf-ghIj&quot;输出：&quot;j-Ih-gfE-dCba&quot;</code></pre><p><strong>示例 3：</strong></p><pre><code class="language-text">输入：s = &quot;Test1ng-Leet=code-Q!&quot;输出：&quot;Qedo1ct-eeLg=ntse-T!&quot;</code></pre><p><strong>提示</strong></p><ul><li>1 &lt;= s.length &lt;= 100</li><li>s 仅由 ASCII 值在范围 [33, 122] 的字符组成</li><li>s 不含 ‘"‘ 或 ‘\‘</li></ul><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/reverse-only-letters/">https://leetcode-cn.com/problems/reverse-only-letters/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>双指针法遍历</p></blockquote><h2 id=""><a href="#" class="headerlink" title=""></a></h2><pre><code class="language-python">class Solution:    def reverseOnlyLetters(self, s: str) -&gt; str:        s=list(s)        head,tail=0,len(s)-1        while(head&lt;tail):            if s[head].isalpha() and s[tail].isalpha():                s[head],s[tail]=s[tail],s[head]    #交换                head+=1                tail-=1            elif (s[head].isalpha()) and (s[tail].isalpha()==False):                tail-=1            elif (s[head].isalpha()==False) and (s[tail].isalpha()):                head+=1            elif (s[head].isalpha()==False) and (s[tail].isalpha()==False):                head+=1                tail-=1                return &#39;&#39;.join(s)</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/9ea3.html</id>
    <link href="https://tianwen42.top/posts/9ea3.html"/>
    <published>2022-02-25T16:47:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目917-仅仅反转字母"><a href="#%E9%A2%98%E7%9B%AE917-%E4%BB%85%E4%BB%85%E5%8F%8D%E8%BD%AC%E5%AD%97%E6%AF%8D" class="headerlink"]]>
    </summary>
    <title>917. 仅仅反转字母</title>
    <updated>2022-04-11T06:14:14.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="斐波那契数列" scheme="https://tianwen42.top/tags/%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97/"/>
    <content>
      <![CDATA[<h2 id="题目509-斐波那契数"><a href="#%E9%A2%98%E7%9B%AE509-%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0" class="headerlink" title="题目509.斐波那契数"></a>题目509.斐波那契数</h2><p>难度：简单</p><p><strong>斐波那契数</strong> （通常用 F(n) 表示）形成的序列称为 <strong>斐波那契数列</strong> 。该数列由 0 和 1 开始，后面的每一项数字都是前面两项数字的和。也就是：</p><pre><code class="language-text">F(0) = 0，F(1) = 1F(n) = F(n - 1) + F(n - 2)，其中 n &gt; 1</code></pre><p>给定 n ，请计算 F(n) 。</p><p><strong>示例 1：</strong></p><pre><code class="language-text">输入：n = 2输出：1解释：F(2) = F(1) + F(0) = 1 + 0 = 1</code></pre><p><strong>示例 2：</strong></p><pre><code class="language-text">输入：n = 3输出：2解释：F(3) = F(2) + F(1) = 1 + 1 = 2</code></pre><p><strong>示例 3：</strong></p><pre><code class="language-text">输入：n = 4输出：3解释：F(4) = F(3) + F(2) = 2 + 1 = 3</code></pre><p><strong>提示：</strong></p><ul><li>0 &lt;= n &lt;= 30</li></ul><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/fibonacci-number/">https://leetcode-cn.com/problems/fibonacci-number/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><pre><code class="language-python">#递归法class Solution:    def fib(self, n: int) -&gt; int:        if(n==0):return 0        elif(n==1):return 1        else:return self.fib(n-1)+self.fib(n-2)</code></pre><p><img src="http://cdn.tianwen42.top/picgo/image-20220225133243080.png" alt="image-20220225133243080"></p><pre><code class="language-python">#通项法import mathclass Solution:    def fib(self, N):        &quot;&quot;&quot;        :type N: int        :rtype: int        &quot;&quot;&quot;        sqrt5=math.sqrt(5)        return round(pow((1+sqrt5)/2,N)/sqrt5)</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/9fe3.html</id>
    <link href="https://tianwen42.top/posts/9fe3.html"/>
    <published>2022-02-25T05:01:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目509-斐波那契数"><a href="#%E9%A2%98%E7%9B%AE509-%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0" class="headerlink"]]>
    </summary>
    <title>509. 斐波那契数</title>
    <updated>2022-04-11T06:14:14.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="DS" scheme="https://tianwen42.top/categories/DS/"/>
    <category term="数据结构" scheme="https://tianwen42.top/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/"/>
    <content>
      <![CDATA[<h2 id="题目13-罗马数字转整数"><a href="#%E9%A2%98%E7%9B%AE13-%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97%E8%BD%AC%E6%95%B4%E6%95%B0" class="headerlink" title="题目13. 罗马数字转整数"></a>题目13. 罗马数字转整数</h2><p>难度：简单</p><p>罗马数字包含以下七种字符: I， V， X， L，C，D 和 M。</p><pre><code class="language-text">字符          数值I             1V             5X             10L             50C             100D             500M             1000</code></pre><p>例如， 罗马数字 2 写做 II ，即为两个并列的 1 。12 写做 XII ，即为 X + II 。 27 写做  XXVII, 即为 XX + V + II 。</p><p>通常情况下，罗马数字中小的数字在大的数字的右边。但也存在特例，例如 4 不写做 IIII，而是 IV。数字 1 在数字 5 的左边，所表示的数等于大数 5 减小数 1 得到的数值 4 。同样地，数字 9 表示为 IX。这个特殊的规则只适用于以下六种情况：</p><ul><li>I 可以放在 V (5) 和 X (10) 的左边，来表示 4 和 9。</li><li>X 可以放在 L (50) 和 C (100) 的左边，来表示 40 和 90。 </li><li>C 可以放在 D (500) 和 M (1000) 的左边，来表示 400 和 900。</li></ul><p>给定一个罗马数字，将其转换成整数。</p><p><strong>示例 1:</strong></p><pre><code class="language-text">输入: s = &quot;III&quot;输出: 3</code></pre><p><strong>示例 2:</strong></p><pre><code class="language-text">输入: s = &quot;IV&quot;输出: 4</code></pre><p><strong>示例 3:</strong></p><pre><code class="language-text">输入: s = &quot;IX&quot;输出: 9</code></pre><p><strong>示例 4:</strong></p><pre><code class="language-text">输入: s = &quot;LVIII&quot;输出: 58解释: L = 50, V= 5, III = 3.</code></pre><p><strong>示例 5:</strong></p><pre><code class="language-text">输入: s = &quot;MCMXCIV&quot;输出: 1994解释: M = 1000, CM = 900, XC = 90, IV = 4.</code></pre><p><strong>提示：</strong></p><ul><li>1 &lt;= s.length &lt;= 15</li><li>s 仅含字符 (‘I’, ‘V’, ‘X’, ‘L’, ‘C’, ‘D’, ‘M’)</li><li>题目数据保证 s 是一个有效的罗马数字，且表示整数在范围 [1, 3999] 内</li><li>题目所给测试用例皆符合罗马数字书写规则，不会出现跨位等情况。</li><li>IL 和 IM 这样的例子并不符合题目要求，49 应该写作 XLIX，999 应该写作 CMXCIX 。</li><li>关于罗马数字的详尽书写规则，可以参考 <a target="_blank" rel="noopener" href="https://b2b.partcommunity.com/community/knowledge/zh_CN/detail/10753/%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97#knowledge_article">罗马数字 - Mathematics </a>。</li></ul><p>来源：力扣（LeetCode）<br>链接：<a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/roman-to-integer/">https://leetcode-cn.com/problems/roman-to-integer/</a><br>著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。</p><h2 id="解题思路"><a href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>替换双位罗马字符，再映射</p></blockquote><h2 id="解题代码"><a href="#%E8%A7%A3%E9%A2%98%E4%BB%A3%E7%A0%81" class="headerlink" title="解题代码"></a>解题代码</h2><pre><code class="language-python">class Solution:    def romanToInt(self, s: str) -&gt; int:        s = s.replace(&#39;CM&#39;, &#39;Q&#39;)        s = s.replace(&#39;CD&#39;, &#39;W&#39;)        s = s.replace(&#39;XC&#39;, &#39;E&#39;)        s = s.replace(&#39;XL&#39;, &#39;R&#39;)        s = s.replace(&#39;IX&#39;, &#39;T&#39;)        s = s.replace(&#39;IV&#39;, &#39;Y&#39;)        keys = &#123;            &#39;Q&#39; : 900,            &#39;W&#39; : 400,            &#39;E&#39; : 90,            &#39;R&#39; : 40,            &#39;T&#39; : 9,            &#39;Y&#39; : 4,            &#39;M&#39; : 1000,            &#39;D&#39; : 500,            &#39;C&#39; : 100,            &#39;L&#39; : 50,            &#39;X&#39; : 10,            &#39;V&#39; : 5,            &#39;I&#39; : 1        &#125;        ans = 0        for ch in s:            ans += keys[ch]                return ans</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/a858.html</id>
    <link href="https://tianwen42.top/posts/a858.html"/>
    <published>2022-02-24T14:04:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="题目13-罗马数字转整数"><a href="#%E9%A2%98%E7%9B%AE13-%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97%E8%BD%AC%E6%95%B4%E6%95%B0" class="headerlink"]]>
    </summary>
    <title>13. 罗马数字转整数</title>
    <updated>2022-04-11T06:14:14.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="基础" scheme="https://tianwen42.top/categories/%E5%9F%BA%E7%A1%80/"/>
    <category term="指针" scheme="https://tianwen42.top/tags/%E6%8C%87%E9%92%88/"/>
    <content>
      <![CDATA[<h3 id="指针"><a href="#%E6%8C%87%E9%92%88" class="headerlink" title="指针"></a>指针</h3><blockquote><ol><li>普通指针</li><li><a href="####%E6%8C%87%E5%90%91const%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%8C%87%E9%92%88">指向 const 对象的指针</a></li><li><a href="####%E6%8C%87%E5%90%91%E9%9D%9Econst%E5%AF%B9%E8%B1%A1%E7%9A%84const%E6%8C%87%E9%92%88">指向 非const 对象的 const 指针</a></li><li><a href="####%E6%8C%87%E5%90%91const%E5%AF%B9%E8%B1%A1%E7%9A%84const%E6%8C%87%E9%92%88">指向 const 对象的 const 指针</a></li></ol></blockquote><p>首先区分引用变量与指针的区别</p><blockquote><p>当创建一个变量时，通过变量名修改和指针修改的安全性不同</p></blockquote><p><img src="http://qiniu.tianwen42.top/picgo/image-20220303143051994.png" alt="image-20220303143051994"></p><h3 id="内存泄漏"><a href="#%E5%86%85%E5%AD%98%E6%B3%84%E6%BC%8F" class="headerlink" title="内存泄漏"></a>内存泄漏</h3><p>tips</p><ul><li><p>创建内存后一定记得free, malloc,free成对出现</p></li><li><p>指针创建后记得要初始化</p></li></ul><p>初始化静态或全局变量不能调用函数，如</p><pre><code class="language-cpp">static int *pi=malloc(sizeof(int));  //编译错误</code></pre><p>改为</p><pre><code class="language-cpp">static int *pi;pi = malloc(sizeof(int));</code></pre>]]>
    </content>
    <id>https://tianwen42.top/posts/e801.html</id>
    <link href="https://tianwen42.top/posts/e801.html"/>
    <published>2022-02-02T01:13:00.000Z</published>
    <summary>
      <![CDATA[<h3 id="指针"><a href="#%E6%8C%87%E9%92%88" class="headerlink" title="指针"></a>指针</h3><blockquote>
<ol>
<li>普通指针</li>
<li><a]]>
    </summary>
    <title>深入理解C指针</title>
    <updated>2022-03-08T15:22:26.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>木木</name>
    </author>
    <category term="生活" scheme="https://tianwen42.top/categories/%E7%94%9F%E6%B4%BB/"/>
    <category term="反省" scheme="https://tianwen42.top/tags/%E5%8F%8D%E7%9C%81/"/>
    <content>
      <![CDATA[<blockquote><p>欲买桂花同载酒，终不似、少年游。 </p></blockquote><p align="center"><img src="http://cdn.tianwen42.top/img/picgo/20210804165007.jpg" alt="Meting" height="500"></p><p>在信息超载的时代，不要停止了思考啊</p><span id="more"></span><h1 id="关于这个暑假"><a href="#%E5%85%B3%E4%BA%8E%E8%BF%99%E4%B8%AA%E6%9A%91%E5%81%87" class="headerlink" title="关于这个暑假"></a>关于这个暑假</h1><p>这暑假，大概有奥运会，暴雨，疫情这么些事。</p><p>时间总是过得非常快的，转眼就到了八月，几天前我还困在matlab建模的泥潭里挣扎着，当然了，现在也还是在泥里。</p><p>几天前路过我这个城市里卖书的一条街，我记得以前老是来这里买书，在那个网络购物还不发达的时代，以前所有的教材书籍都要来这买，每次开学都人挤人，想来已经有好多年没来了，这次来这儿，是陪我在上小学的妹妹，我说要送她几本书，让她随便挑书，最后她愣是没挑出来，倒是我买了两本书，我高中时候就会看这两本书，他们着实为我的高中生活增加了些颜色。想起来系统的看书是什么时候呢，我记得大一的时候借了很多书，虽然不一定看完，也都算认真的看了看，现在借书看一下子就耐不住性子了，是不是看多了视频之类的内容，而接受不来慢下来的内容了？我一时间竟感到的羞愧.</p><p><img src="http://cdn.tianwen42.top/img/picgo/20210804164932.jpg" alt="57b30981a3a47c6f67e8b380882843a"></p><p><img src="http://cdn.tianwen42.top/img/picgo/20210804165007.jpg" alt="4e3a216d4de8527aa8e0dc42751efbc"></p><p>我个人很喜欢一句话，<strong>用脚去丈量能够企及的大地</strong></p><h1 id="关于信息超载"><a href="#%E5%85%B3%E4%BA%8E%E4%BF%A1%E6%81%AF%E8%B6%85%E8%BD%BD" class="headerlink" title="关于信息超载"></a>关于信息超载</h1><p><strong>＂我们被信息淹没，但却渴求知识.＂</strong>（奈斯比特）</p><p>为什么信息过载会产生焦虑？因为你接受的信息没办法给你的生活带来好的转变，但这些信息、挑选信息的过程，却在实实在在地消耗你的有限资源——<strong>时间。</strong></p><p>就我来说，最近的状态实在是不容乐观，国家讲究治理体系和治理能力，那我个人最近的治理效率可谓是低谷，投入与产出之比很低，每天投入的大概是靠着不背单词的几十个单词，知乎和bilibili实在是信息量爆炸，我个人还是很喜欢bilibili的，起初接触到，是因为上面有非常多的课程，但是使用着就会发现，关注越来越多，收藏也越来越多，弹幕本来是互动的好工具，现在我有点儿神经衰落了，什么内容的视频都推送，一股脑的给你，原先我是很讨厌抖音这种短视频内容的，后来发觉b站也愈发累赘了，趋于同化，我如果不能主导这些信息的话，我宁愿不接受这些，索性我卸载了知乎与bilibili，这与我不用QQ是同样的原因，我的b站本来有120+的关注，今天索性清理一下，只有20+了，</p><p>心灵的明亮与模糊，保持积极的向上的很很不容易，在信息超载的时代，不要停止了思考，<strong>多则惑，少则得</strong>，如是而已.</p><p><img src="http://cdn.tianwen42.top/img/picgo/20210806103651.png" alt="image-20210806103651055"></p><h1 id="关于道德"><a href="#%E5%85%B3%E4%BA%8E%E9%81%93%E5%BE%B7" class="headerlink" title="关于道德"></a>关于道德</h1><blockquote><p>齐宣王问曰：“齐桓、晋文之事可得闻乎？”<br>孟子对曰：“仲尼之徒无道桓、文之事者，是以后世无传焉。臣未之闻也。无以，则王乎？”<br>曰：“德何如，则可以王矣？”<br>曰：“保民而王，莫之能御也。”<br>曰：“若寡人者，可以保民乎哉？”<br>曰：“可。”<br>曰：“何由知吾可也？”<br>曰：“臣闻之胡龁曰，王坐于堂上，有牵牛而过堂下者，王见之，曰：‘牛何之？对曰：‘将以衅钟。’王曰：‘舍之！吾不忍其觳觫，若无罪而就死地。’对曰：‘然则废衅钟与？’曰：‘何可废也？以羊易之！’不识有诸？”<br>曰：“有之。”<br>曰：“是心足以王矣。百姓皆以王为爱也，臣固知王之不忍也。”<br>王曰：“然。诚有百姓者。齐国虽褊小，吾何爱一牛？即不忍其觳觫，若无罪而就死地，故以羊易之也。”<br>曰：“王无异于百姓之以王为爱也。以小易大，彼恶知之？王若隐其无罪而就死地，则牛羊何择焉？” 王笑曰：“是诚何心哉？我非爱其财。而易之以羊也，宜乎百姓之谓我爱也。”<br>曰：“无伤也，是乃仁术也，见牛未见羊也。君子之于禽兽也，见其生，不忍见其死；闻其声，不忍食其肉。是以君子远庖厨也。”</p></blockquote><p>就事论事的话，“君子远庖厨”本身就是一种伪善。道德本就难以单一的界定，时至今日，这两种道德仍然可能发生矛盾，我们可能仍然会面临相似的问题</p><p><strong>城市上空我们这一排透着灯光的窗户，对于昏黄街道上漫步的行人来说，一定蕴藏着几许人生的秘密。我也看到了这样一位行人，正在抬头仰望，独自思索。我既在其中，又在其外，对人生的变幻无穷感到陶醉又厌恶</strong></p>]]>
    </content>
    <id>https://tianwen42.top/posts/d9c69240.html</id>
    <link href="https://tianwen42.top/posts/d9c69240.html"/>
    <published>2021-08-04T08:01:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>欲买桂花同载酒，终不似、少年游。 </p>
</blockquote>
<p align="center">
<img src="http://cdn.tianwen42.top/img/picgo/20210804165007.jpg"]]>
    </summary>
    <title>仲夏</title>
    <updated>2022-06-29T16:40:56.000Z</updated>
  </entry>
</feed>
