<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>leetcode &#8211; JSAlgorithm</title>
	<atom:link href="https://jsalgorithm.com/tag/leetcode/feed/" rel="self" type="application/rss+xml" />
	<link>https://jsalgorithm.com</link>
	<description></description>
	<lastBuildDate>Wed, 20 May 2020 17:34:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.15</generator>
<site xmlns="com-wordpress:feed-additions:1">177240629</site>	<item>
		<title>Array Plus One</title>
		<link>https://jsalgorithm.com/2020/05/20/array-plus-one/</link>
					<comments>https://jsalgorithm.com/2020/05/20/array-plus-one/#respond</comments>
		
		<dc:creator><![CDATA[Ronald]]></dc:creator>
		<pubDate>Wed, 20 May 2020 17:34:14 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[leetcode]]></category>
		<category><![CDATA[plusone]]></category>
		<guid isPermaLink="false">http://50.19.13.106/?p=128</guid>

					<description><![CDATA[let plusOne = function(digits) { let carry = 1; for (let i = digits.length - 1; i &#62;= 0; i--) { let sum = digits[i] + carry; if (sum &#62;= 10) { digits[i] = 0; carry = 1; } else { digits[i] = sum; carry = 0; } } if (carry === 1) digits.unshift(carry); return [&#8230;]]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted">let plusOne = function(digits) {<br><br>    let carry = 1;<br>    for (let i = digits.length - 1; i &gt;= 0; i--) {<br>        let sum = digits[i] + carry;<br>        if (sum &gt;= 10) {<br>            digits[i] = 0;<br>            carry = 1;<br>        }<br>        else {<br>            digits[i] = sum;<br>            carry = 0;<br>        }<br>    }<br><br>    if (carry === 1) digits.unshift(carry);<br><br>    return digits;<br>};</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jsalgorithm.com/2020/05/20/array-plus-one/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">128</post-id>	</item>
		<item>
		<title>LinkedList Palindrome</title>
		<link>https://jsalgorithm.com/2020/05/20/linkedlist-palindrome/</link>
					<comments>https://jsalgorithm.com/2020/05/20/linkedlist-palindrome/#respond</comments>
		
		<dc:creator><![CDATA[Ronald]]></dc:creator>
		<pubDate>Wed, 20 May 2020 17:20:07 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[Loop]]></category>
		<category><![CDATA[leetcode]]></category>
		<category><![CDATA[linkedlist]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[palindrome]]></category>
		<category><![CDATA[stack]]></category>
		<guid isPermaLink="false">http://50.19.13.106/?p=126</guid>

					<description><![CDATA[let isPalindrome = function(head) { let slow = head, fast = head, val = [slow.val]; while (fast.next) { if (fast.next.next) { fast = fast.next.next; slow = slow.next; val.push(slow.val); } else { fast = fast.next; slow = slow.next; } } while (slow) { if (slow.val !== val.pop()) { return false; } slow = slow.next; } return [&#8230;]]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted">let isPalindrome = function(head) {<br><br>    let slow = head, fast = head, val = [slow.val];<br><br>    while (fast.next) {<br>        if (fast.next.next) {<br>            fast = fast.next.next;<br>            slow = slow.next;<br>            val.push(slow.val);<br>        }<br>        else {<br>            fast = fast.next;<br>            slow = slow.next;<br>        }<br>    }<br><br>    while (slow) {<br>        if (slow.val !== val.pop()) {<br>            return false;<br>        }<br>        slow = slow.next;<br>    }<br><br>    return val.length === 0;<br>};</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jsalgorithm.com/2020/05/20/linkedlist-palindrome/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">126</post-id>	</item>
		<item>
		<title>Happy Number</title>
		<link>https://jsalgorithm.com/2020/05/20/happy-number/</link>
					<comments>https://jsalgorithm.com/2020/05/20/happy-number/#respond</comments>
		
		<dc:creator><![CDATA[Ronald]]></dc:creator>
		<pubDate>Wed, 20 May 2020 12:41:18 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[Recursion]]></category>
		<category><![CDATA[leetcode]]></category>
		<category><![CDATA[recursion]]></category>
		<guid isPermaLink="false">http://50.19.13.106/?p=122</guid>

					<description><![CDATA[let isHappy = function(n) { let visited = {}; function sumOfSquare(num) { if (visited[num]) return false; visited[num] = true; let sum = 0; while (num &#62; 0) { let d = num % 10; //? num = Math.floor(num / 10); //? sum += d * d; } if (sum === 1) { return true; } [&#8230;]]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted">let isHappy = function(n) {<br>    let visited = {};<br><br>    function sumOfSquare(num) {<br>        if (visited[num]) return false;<br>        visited[num] = true;<br><br>        let sum = 0;<br>        while (num &gt; 0) {<br>            let d = num % 10; //?<br>            num = <strong><em>Math</em></strong>.floor(num / 10); //?<br>            sum += d * d;<br>        }<br><br>        if (sum === 1) {<br>            return true;<br>        }<br>        else {<br>            return sumOfSquare(sum);<br>        }<br>    }<br>    <br>    return sumOfSquare(n);<br>};</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jsalgorithm.com/2020/05/20/happy-number/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">122</post-id>	</item>
		<item>
		<title>MaxStack</title>
		<link>https://jsalgorithm.com/2020/05/20/maxstack/</link>
					<comments>https://jsalgorithm.com/2020/05/20/maxstack/#respond</comments>
		
		<dc:creator><![CDATA[Ronald]]></dc:creator>
		<pubDate>Wed, 20 May 2020 03:15:12 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[leetcode]]></category>
		<guid isPermaLink="false">http://50.19.13.106/?p=120</guid>

					<description><![CDATA[class MaxStack { constructor() { this.results = []; this.sorted = []; } pop() { const val = this.results.pop(); this.sorted.splice(this.sorted.lastIndexOf(val), 1); return val; } push(x) { this.results.push(x); this.sorted = [...this.results].sort((x, y) =&#62; x - y); } top() { return this.results[this.results.length - 1]; } popMax() { const val = this.sorted.pop(); this.results.splice(this.results.lastIndexOf(val), 1); return val; } peekMax() { [&#8230;]]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted">class MaxStack {<br>    constructor() {<br>        this.results = [];<br>        this.sorted = [];<br>    }<br><br>    pop() {<br>        const val = this.results.pop();<br>        this.sorted.splice(this.sorted.lastIndexOf(val), 1);<br>        return val;<br>    }<br><br>    push(x) {<br>        this.results.push(x);<br>        this.sorted = [...this.results].sort((x, y) =&gt; x - y);<br>    }<br><br>    top() {<br>        return this.results[this.results.length - 1];<br>    }<br><br>    popMax() {<br>        const val = this.sorted.pop();<br>        this.results.splice(this.results.lastIndexOf(val), 1);<br>        return val;<br>    }<br><br>    peekMax() {<br>        return this.sorted[this.sorted.length - 1];<br>    }<br><br>}</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jsalgorithm.com/2020/05/20/maxstack/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">120</post-id>	</item>
		<item>
		<title>MinStack</title>
		<link>https://jsalgorithm.com/2020/05/20/minstack/</link>
					<comments>https://jsalgorithm.com/2020/05/20/minstack/#respond</comments>
		
		<dc:creator><![CDATA[Ronald]]></dc:creator>
		<pubDate>Wed, 20 May 2020 03:03:29 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[leetcode]]></category>
		<guid isPermaLink="false">http://50.19.13.106/?p=118</guid>

					<description><![CDATA[class MinStack { constructor() { this.result = []; this.min = Number.MAX_SAFE_INTEGER; } push(x) { this.result.push(x) this.min = Math.min(x, this.min); }; pop() { let val = this.result.pop() if (val === this.min) { this.min = Math.min(...this.result); } }; top() { return this.result[this.result.length - 1]; }; getMin() { return this.min; };}]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted">class MinStack {<br>    constructor() {<br>        this.result = [];<br>        this.min = <strong><em>Number</em></strong>.MAX_SAFE_INTEGER;<br>    }<br><br>    push(x) {<br>        this.result.push(x)<br>        this.min = <strong><em>Math</em></strong>.min(x, this.min);<br>    };<br><br>    pop() {<br>        let val = this.result.pop()<br>        if (val === this.min) {<br>            this.min = <strong><em>Math</em></strong>.min(...this.result);<br>        }<br>    };<br><br>    top() {<br>        return this.result[this.result.length - 1];<br>    };<br><br>    getMin() {<br>        return this.min;<br>    };<br>}</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jsalgorithm.com/2020/05/20/minstack/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">118</post-id>	</item>
		<item>
		<title>Longest Common Prefix</title>
		<link>https://jsalgorithm.com/2020/05/20/longest-common-prefix/</link>
					<comments>https://jsalgorithm.com/2020/05/20/longest-common-prefix/#respond</comments>
		
		<dc:creator><![CDATA[Ronald]]></dc:creator>
		<pubDate>Wed, 20 May 2020 02:44:25 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[leetcode]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">http://50.19.13.106/?p=114</guid>

					<description><![CDATA[let longestCommonPrefix = function(strs) { if (!strs.length) return ''; let index = 0, curr = ''; for (;;) { for (let i = 0; i &#60; strs.length; i++) { if (strs[i].length &#60;= index) { return strs[0].substring(0, index); //? } if (curr === '') curr = strs[i][index]; if (curr !== strs[i][index]) { return strs[0].substring(0, index); } [&#8230;]]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted">let longestCommonPrefix = function(strs) {<br><br>    if (!strs.length) return '';<br><br>    let index = 0, curr = '';<br>    for (;;)<br>    {<br>        for (let i = 0; i &lt; strs.length; i++) {<br>            if (strs[i].length &lt;= index) {<br>                return strs[0].substring(0, index); //?<br>            }<br>            if (curr === '') curr = strs[i][index];<br>            if (curr !== strs[i][index]) {<br>                return strs[0].substring(0, index);<br>            }<br>            if (i === strs.length - 1) {<br>                curr = '';<br>                index++<br>            }<br>        }<br>    }<br><br>    return '';<br>};</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jsalgorithm.com/2020/05/20/longest-common-prefix/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">114</post-id>	</item>
		<item>
		<title>Pascal Triangle</title>
		<link>https://jsalgorithm.com/2020/05/20/pascal-triangle/</link>
					<comments>https://jsalgorithm.com/2020/05/20/pascal-triangle/#respond</comments>
		
		<dc:creator><![CDATA[Ronald]]></dc:creator>
		<pubDate>Wed, 20 May 2020 02:17:45 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[Loop]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[leetcode]]></category>
		<category><![CDATA[loop]]></category>
		<guid isPermaLink="false">http://50.19.13.106/?p=112</guid>

					<description><![CDATA[let generate = function(numRows) { if (numRows === 0) return []; let result = []; for (let i = 1; i &#60;= numRows;i++) { let row = []; for (let j = 0; j &#60; i; j++) { if (j === 0 &#124;&#124; j === i - 1) { row[j] = 1; } else { [&#8230;]]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted">let generate = function(numRows) {<br><br>    if (numRows === 0) return [];<br><br>    let result = [];<br>    for (let i = 1; i &lt;= numRows;i++) {<br>        let row = [];<br>        for (let j = 0; j &lt; i; j++) {<br>            if (j === 0 || j === i - 1) {<br>                row[j] = 1;<br>            }<br>            else {<br>                row[j] = result[i - 2][j - 1] + result[i - 2][j];<br>            }<br>        }<br>        result.push(row);<br>    }<br><br>    return result;<br>};</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jsalgorithm.com/2020/05/20/pascal-triangle/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">112</post-id>	</item>
		<item>
		<title>Palindrome</title>
		<link>https://jsalgorithm.com/2020/05/20/palindrome/</link>
					<comments>https://jsalgorithm.com/2020/05/20/palindrome/#respond</comments>
		
		<dc:creator><![CDATA[Ronald]]></dc:creator>
		<pubDate>Wed, 20 May 2020 01:55:55 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[Loop]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[leetcode]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">http://50.19.13.106/?p=110</guid>

					<description><![CDATA[let isPalindrome = function(s) { let start = 0, end = s.length - 1, regex = /\w/i; while (start &#60; end) { if (!s[start].match(regex)) { start++; } else if (!s[end].match(regex)) { end--; } else { if (s[start].toLowerCase() !== s[end].toLowerCase()) return false; start++; end--; } } return true;}]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted">let isPalindrome = function(s) {<br>    let start = 0, end = s.length - 1, regex = /\w/i;<br>    while (start &lt; end) {<br>        if (!s[start].match(regex)) {<br>            start++;<br>        }<br>        else if (!s[end].match(regex)) {<br>            end--;<br>        }<br>        else {<br>            if (s[start].toLowerCase() !== s[end].toLowerCase()) return false;<br>            start++;<br>            end--;<br>        }<br>    }<br>    return true;<br>}</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jsalgorithm.com/2020/05/20/palindrome/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">110</post-id>	</item>
		<item>
		<title>Roman To Int</title>
		<link>https://jsalgorithm.com/2020/05/20/roman-to-int/</link>
					<comments>https://jsalgorithm.com/2020/05/20/roman-to-int/#respond</comments>
		
		<dc:creator><![CDATA[Ronald]]></dc:creator>
		<pubDate>Wed, 20 May 2020 01:43:13 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[Loop]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[leetcode]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">http://50.19.13.106/?p=108</guid>

					<description><![CDATA[let romanToInt = function(s) { if (!s) return 0; let mapping = { 'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000 } let result = 0; for (let i = s.length - 1; i &#62;= 0;) { if (mapping[s[i]] &#62; mapping[s[i - 1]]) { result += mapping[s[i]] - mapping[s[i [&#8230;]]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted">let romanToInt = function(s) {<br>    if (!s) return 0;<br><br>    let mapping = {<br>        'I': 1,<br>        'V': 5,<br>        'X': 10,<br>        'L': 50,<br>        'C': 100,<br>        'D': 500,<br>        'M': 1000<br>    }<br><br>    let result = 0;<br>    for (let i = s.length - 1; i &gt;= 0;) {<br>        if (mapping[s[i]] &gt; mapping[s[i - 1]]) {<br>            result += mapping[s[i]] - mapping[s[i - 1]];<br>            i -= 2;<br>        }<br>        else {<br>            result += mapping[s[i]];<br>            i -= 1;<br>        }<br>    }<br><br>    return result;<br>}</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jsalgorithm.com/2020/05/20/roman-to-int/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">108</post-id>	</item>
		<item>
		<title>Unique Paths with Obstacles</title>
		<link>https://jsalgorithm.com/2020/05/18/unique-paths-with-obstacles/</link>
					<comments>https://jsalgorithm.com/2020/05/18/unique-paths-with-obstacles/#respond</comments>
		
		<dc:creator><![CDATA[Ron]]></dc:creator>
		<pubDate>Mon, 18 May 2020 22:32:55 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[Dynamic Programming]]></category>
		<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[dynamic-programming]]></category>
		<category><![CDATA[leetcode]]></category>
		<category><![CDATA[matrix]]></category>
		<guid isPermaLink="false">http://50.19.13.106/?p=106</guid>

					<description><![CDATA[let uniquePathsWithObstacles = function(obstacleGrid) { if (!obstacleGrid &#124;&#124; !obstacleGrid.length) return 0; function markNextRowsAsZero(col) { for (let i = col; i &#60; maxCol; i++) { obstacleGrid[0][i] = 0; } } function markNextColumnsAsZero(row) { for (let i = row; i &#60; maxRow; i++) { obstacleGrid[i][0] = 0; } } let maxRow = obstacleGrid.length, maxCol = obstacleGrid[0].length, OBSTACLE [&#8230;]]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted">let uniquePathsWithObstacles = function(obstacleGrid) {<br><br>    if (!obstacleGrid || !obstacleGrid.length) return 0;<br><br>    function markNextRowsAsZero(col) {<br>        for (let i = col; i &lt; maxCol; i++) {<br>            obstacleGrid[0][i] = 0;<br>        }<br>    }<br>    function markNextColumnsAsZero(row) {<br>        for (let i = row; i &lt; maxRow; i++) {<br>            obstacleGrid[i][0] = 0;<br>        }<br>    }<br><br>    let maxRow = obstacleGrid.length,<br>        maxCol = obstacleGrid[0].length,<br>        OBSTACLE = 1, VISITED = -1;<br><br>    // first block is obstacle return 0;<br>    if (obstacleGrid[0][0] === OBSTACLE) {<br>        return 0;<br>    }<br><br>    // mark all first rows as either 1 or zero<br>    for (let col = 0; col &lt; maxCol;col++) {<br>        if (obstacleGrid[0][col] === OBSTACLE) {<br>            markNextRowsAsZero(col);<br>            break;<br>        }<br>        else {<br>            obstacleGrid[0][col] = 1;<br>        }<br>    }<br><br>    // mark all first columns as either 1 or zero<br>    for (let row = 1; row &lt; maxRow;row++) {<br>        if (obstacleGrid[row][0] === OBSTACLE) {<br>            markNextColumnsAsZero(row);<br>            break;<br>        }<br>        else {<br>            obstacleGrid[row][0] = 1;<br>        }<br>    }<br><br>    for (let row = 1; row &lt; maxRow;row++) {<br>        for (let col = 1; col &lt; maxCol;col++) {<br>            if (obstacleGrid[row][col] === OBSTACLE) {<br>                obstacleGrid[row][col] = 0;<br>            }<br>            else {<br>                obstacleGrid[row][col] =<br>                    obstacleGrid[row - 1][col] +<br>                    obstacleGrid[row][col - 1];<br>            }<br><br>        }<br>    }<br><br>    return obstacleGrid[maxRow - 1][maxCol - 1];<br>};</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jsalgorithm.com/2020/05/18/unique-paths-with-obstacles/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">106</post-id>	</item>
	</channel>
</rss>
