문제

문제 풀이
using System;
class Solution
{
public int solution(int[] sticker)
{
if (sticker.Length == 1)
return sticker[0];
int[] dp1 = new int[sticker.Length];
int[] dp2 = new int[sticker.Length];
dp1[0] = sticker[0];
dp1[1] = Math.Max(sticker[0], sticker[1]);
for (int i = 2; i < sticker.Length - 1; i++)
{
dp1[i] = Math.Max(dp1[i - 1], dp1[i - 2] + sticker[i]);
}
dp2[0] = 0;
dp2[1] = sticker[1];
for (int i = 2; i < sticker.Length; i++)
{
dp2[i] = Math.Max(dp2[i - 1], dp2[i - 2] + sticker[i]);
}
return Math.Max(dp1[sticker.Length - 2], dp2[sticker.Length - 1]);
}
}