連結:https://leetcode.com/problems/house-robber/description/
class Solution {
public int rob(int[] nums) {
int prev = nums[0],prev2=0,curr;
for(int i=1;i<nums.length;i++)
{
int notSkippingCurrIDX = prev2 + nums[i];
int skippingCurrIDX = prev;
curr = Math.max(notSkippingCurrIDX,skippingCurrIDX);
prev2 = prev;
prev = curr;
}
return prev;
}
}
連結:https://leetcode.com/problems/count-sorted-vowel-strings/description/
a -> aa, ae, ai, ao, au
e -> ee, ei, eo, eu
i -> ii, io, iu
0 -> oo, ou
u -> uu
class Solution {
int a=1, e=1, i=1, o=1, u=1;
public int countVowelStrings(int n) {
for(int j=1; j<n; j++){
increment();
}
return a+e+i+o+u;
}
private void increment() {
a = a+e+i+o+u;
e = e+i+o+u;
i = i+o+u;
o = o+u;
}
}