1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (English)/绘制直线(English) [draw-line-lcci].html

19 lines
1.2 KiB
HTML

<p>A monochrome screen is stored as a single array of int, allowing 32 consecutive pixels to be stored in one int. The screen has width <code>w</code>, where <code>w</code> is divisible by 32&nbsp;(that is, no byte will be split across rows). The height of the screen, of course, can be derived from the length of the array and the width. Implement a function that draws a horizontal line from <code>(x1, y)</code> to <code>(x2, y)</code>.</p>
<p>Given the length of the array, the width of the array (in bit), start position <code>x1</code>&nbsp;(in bit) of the line, end position <code>x2</code> (in bit) of the line and the row number&nbsp;<code>y</code> of the line, return the array after drawing.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>: length = 1, w = 32, x1 = 30, x2 = 31, y = 0
<strong> Output</strong>: [3]
<strong> Explanation</strong>: After drawing a line from (30, 0) to (31, 0), the screen becomes [0b000000000000000000000000000000011].
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>: length = 3, w = 96, x1 = 0, x2 = 95, y = 0
<strong> Output</strong>: [-1, -1, -1]
</pre>