<?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>width Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/width/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/width/</link>
	<description></description>
	<lastBuildDate>Sat, 29 Apr 2023 15:23:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>width Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/width/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 2639. Find the Width of Columns of a Grid</title>
		<link>https://zxi.mytechroad.com/blog/simulation/leetcode-2639-find-the-width-of-columns-of-a-grid/</link>
					<comments>https://zxi.mytechroad.com/blog/simulation/leetcode-2639-find-the-width-of-columns-of-a-grid/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sat, 29 Apr 2023 15:22:36 +0000</pubDate>
				<category><![CDATA[Simulation]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[length]]></category>
		<category><![CDATA[matrix]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[width]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=10006</guid>

					<description><![CDATA[<p>You are given a&#160;0-indexed&#160;m x n&#160;integer matrix&#160;grid. The width of a column is the maximum&#160;length&#160;of its integers. For example, if&#160;grid = [[-10], [3], [12]], the&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-2639-find-the-width-of-columns-of-a-grid/">花花酱 LeetCode 2639. Find the Width of Columns of a Grid</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>You are given a&nbsp;<strong>0-indexed</strong>&nbsp;<code>m x n</code>&nbsp;integer matrix&nbsp;<code>grid</code>. The width of a column is the maximum&nbsp;<strong>length&nbsp;</strong>of its integers.</p>



<ul><li>For example, if&nbsp;<code>grid = [[-10], [3], [12]]</code>, the width of the only column is&nbsp;<code>3</code>&nbsp;since&nbsp;<code>-10</code>&nbsp;is of length&nbsp;<code>3</code>.</li></ul>



<p>Return&nbsp;<em>an integer array</em>&nbsp;<code>ans</code>&nbsp;<em>of size</em>&nbsp;<code>n</code>&nbsp;<em>where</em>&nbsp;<code>ans[i]</code>&nbsp;<em>is the width of the</em>&nbsp;<code>i<sup>th</sup></code>&nbsp;<em>column</em>.</p>



<p>The&nbsp;<strong>length</strong>&nbsp;of an integer&nbsp;<code>x</code>&nbsp;with&nbsp;<code>len</code>&nbsp;digits is equal to&nbsp;<code>len</code>&nbsp;if&nbsp;<code>x</code>&nbsp;is non-negative, and&nbsp;<code>len + 1</code>&nbsp;otherwise.</p>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> grid = [[1],[22],[333]]
<strong>Output:</strong> [3]
<strong>Explanation:</strong> In the 0<sup>th</sup> column, 333 is of length 3.
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> grid = [[-15,1,3],[15,7,12],[5,6,-2]]
<strong>Output:</strong> [3,1,2]
<strong>Explanation:</strong> 
In the 0<sup>th</sup> column, only -15 is of length 3.
In the 1<sup>st</sup> column, all integers are of length 1. 
In the 2<sup>nd</sup> column, both 12 and -2 are of length 2.
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>m == grid.length</code></li><li><code>n == grid[i].length</code></li><li><code>1 &lt;= m, n &lt;= 100</code></li><li><code>-10<sup>9</sup> &lt;= grid[r][c] &lt;= 10<sup>9</sup></code></li></ul>



<h2><strong>Solution: Simulation</strong></h2>



<p>Note: width of &#8216;0&#8217; is 1.</p>



<p>Time complexity: O(m*n*log(x))<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  vector&lt;int&gt; findColumnWidth(vector&lt;vector&lt;int&gt;&gt;&amp; grid) {
    vector&lt;int&gt; ans;
    for (int j = 0; j &lt; grid[0].size(); ++j) {
      int maxWidth = 1;
      for (int i = 0; i &lt; grid.size(); ++i) {
        int x = grid[i][j];
        int width = 0;        
        if (x &lt; 0) {
          x = -x;
          ++width;
        }
        while (x) {
          x /= 10;
          ++width;
        }        
        maxWidth = max(maxWidth, width);
      }
      ans.push_back(maxWidth);
    }
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-2639-find-the-width-of-columns-of-a-grid/">花花酱 LeetCode 2639. Find the Width of Columns of a Grid</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/simulation/leetcode-2639-find-the-width-of-columns-of-a-grid/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
