0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

アルゴリズムとデータ構造1の質問

Last updated at Posted at 2016-11-23

配列の要素の差が、最大値になる値を探す問題です。
ただし、配列の値が、「後から先」へは計算できるが「先から後」へは計算できない。

x = array[i]
y = array[j]
x - y が最大になる値を求める。だたし、「i > j」でなければならない

実際のコード例

arrs = [4, 3, 2] #回答は-1

こういった計算は、「j < i」になるので認められない。

4 - 2

例えば、こういったケースの場合 

arrs = [5, 3, 1, 3, 4, 3] #回答は3

5 - 1は正解ではない。arrs[0] - arrs[2]で「i < j」になっている。
4 - 1が正解。arrs[4] - arrs[2]で「i > j」になっている。

ruby
4 - 1 = 3

These are all example.

arrs = [5, 3, 1, 3, 4, 3, 7, 8, 15] #15 - 1。回答は14
arrs = [5, 3, 1, 3, 4, 3]  #4 - 1。回答は3
arrs = [4, 3, 2] #2 - 3。回答は-1
arrs = [8, 6, 3] #6 - 8。回答は-2
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?