Remove One Element to Make the Array Strictly Increasing


Submit solution

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type

題目說明

輸入一個數列,如果從該數列移除一個元素,可以使得該陣列成為嚴格遞增數列,則輸出1,否則輸出0。如果該數列原本就已經是嚴格遞增數列,則輸出1。

嚴格遞增數列定義: 數列中的每個元素都比前面的元素更大。

這一題的解答不需要使用雙重迴圈(nested loops)也不需要使用ArrayList。

本題類似LeetCode 1909

輸入格式

數列長度k,以及該數列的內容共k個數字

輸入值範圍

2 <= k <= 1000,其他數字皆大於等於1且小於等於1000。

sample input 1

5 1 2 10 5 7

sample output 1

1

說明

因為1 2 10 5 7在移除10之後就成為嚴格遞增數列

sample input 2

4 2 3 1 2

sample output 2

0

說明

因為2 3 1 2在移除任何數字之後都無法成為嚴格遞增數列

Comments

There are no comments at the moment.