<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>leetcode &#8211; Antonio</title>
	<atom:link href="/tag/leetcode/feed/" rel="self" type="application/rss+xml" />
	<link>https://nstar.ltd</link>
	<description></description>
	<lastBuildDate>Sat, 15 Mar 2025 18:14:17 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>一些常用算法（LeetCode.面）</title>
		<link>/%e4%b8%80%e4%ba%9b%e5%b8%b8%e7%94%a8%e7%ae%97%e6%b3%95%ef%bc%88leetcode-%e9%9d%a2%ef%bc%89/</link>
					<comments>/%e4%b8%80%e4%ba%9b%e5%b8%b8%e7%94%a8%e7%ae%97%e6%b3%95%ef%bc%88leetcode-%e9%9d%a2%ef%bc%89/#respond</comments>
		
		<dc:creator><![CDATA[Antonio]]></dc:creator>
		<pubDate>Sat, 17 Aug 2024 15:12:35 +0000</pubDate>
				<category><![CDATA[博客]]></category>
		<category><![CDATA[笔记]]></category>
		<category><![CDATA[leetcode]]></category>
		<category><![CDATA[算法]]></category>
		<guid isPermaLink="false">http://192.168.1.8/?p=80</guid>

					<description><![CDATA[罗列一些常用算法（不定期更新）： 1.双指针-快慢指针 2.摩尔投票算法（求众数）]]></description>
										<content:encoded><![CDATA[
<p>罗列一些常用算法（不定期更新）：</p>



<ul class="wp-block-list">
<li>双指针-快慢指针</li>



<li>摩尔投票算法</li>
</ul>



<p>1.双指针-快慢指针</p>



<pre class="wp-block-code"><code>// 时间复杂度：O(n)
// 空间复杂度：O(1)
class Solution {
public:
int removeElement(vector&lt;int>&amp; nums, int val) {
int slowIndex = 0;
for (int fastIndex = 0; fastIndex &lt; nums.size(); fastIndex++) {
if (val != nums&#91;fastIndex]) {
nums&#91;slowIndex++] = nums&#91;fastIndex];
 }
 }
return slowIndex;
 }
};</code></pre>



<p>2.摩尔投票算法（求众数）</p>



<pre class="wp-block-code"><code>// 摩尔投票算法
int majorityElement(int* nums, int numsSize) {
    int count = 0;
    int candidate = 0;

    for (int i = 0; i &lt; numsSize; i++) {
        if (count == 0) {
            candidate = nums&#91;i];
        }
        count += (nums&#91;i] == candidate) ? 1 : -1;
    }
    return candidate;
} </code></pre>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>/%e4%b8%80%e4%ba%9b%e5%b8%b8%e7%94%a8%e7%ae%97%e6%b3%95%ef%bc%88leetcode-%e9%9d%a2%ef%bc%89/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
