Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 36a87b1

Browse files
Create README - LeetHub
1 parent 55c22a6 commit 36a87b1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<h2><a href="https://leetcode.com/problems/sum-of-absolute-differences-in-a-sorted-array/"><div id="big-omega-company-tags"><div id="big-omega-topbar"><div class="companyTagsContainer" style="overflow-x: scroll; flex-wrap: nowrap;"><div class="companyTagsContainer--tag">No companies found for this problem</div></div><div class="companyTagsContainer--chevron"><div><svg version="1.1" id="icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 32 32" fill="#4087F1" xml:space="preserve" style="width: 20px;"><polygon points="16,22 6,12 7.4,10.6 16,19.2 24.6,10.6 26,12 "></polygon><rect id="_x3C_Transparent_Rectangle_x3E_" class="st0" fill="none" width="32" height="32"></rect></svg></div></div></div></div>1685. Sum of Absolute Differences in a Sorted Array</a></h2><h3>Medium</h3><hr><div><p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p>
2+
3+
<p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute differences</strong> between </em><code>nums[i]</code><em> and all the other elements in the array.</em></p>
4+
5+
<p>In other words, <code>result[i]</code> is equal to <code>sum(|nums[i]-nums[j]|)</code> where <code>0 &lt;= j &lt; nums.length</code> and <code>j != i</code> (<strong>0-indexed</strong>).</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<pre><strong>Input:</strong> nums = [2,3,5]
11+
<strong>Output:</strong> [4,3,5]
12+
<strong>Explanation:</strong> Assuming the arrays are 0-indexed, then
13+
result[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,
14+
result[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,
15+
result[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.
16+
</pre>
17+
18+
<p><strong class="example">Example 2:</strong></p>
19+
20+
<pre><strong>Input:</strong> nums = [1,4,6,8,10]
21+
<strong>Output:</strong> [24,15,13,15,21]
22+
</pre>
23+
24+
<p>&nbsp;</p>
25+
<p><strong>Constraints:</strong></p>
26+
27+
<ul>
28+
<li><code>2 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
29+
<li><code>1 &lt;= nums[i] &lt;= nums[i + 1] &lt;= 10<sup>4</sup></code></li>
30+
</ul>
31+
</div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /