Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public int getIndexByDay(String S) {
- switch(S) {
- case "Mon": return 0;
- case "Tue": return 1;
- case "Wed": return 2;
- case "Thu": return 3;
- case "Fri": return 4;
- case "Sat": return 5;
- case "Sun": return 6;
- }
- return -1;
- }
- public static String[] initArray() {
- String[] arr = new String[7];
- arr[0] = "Mon";
- arr[1] = "Tue";
- arr[2] = "Wed";
- arr[3] = "Thu";
- arr[4] = "Fri";
- arr[5] = "Sat";
- arr[6] = "Sun";
- return arr;
- }
- public String solution(String S, int k) {
- String[] arr = initArray();
- int currentIndex = getIndexByDay(S);
- int toAdd = k % 7;
- int indexDayToBe = (currentIndex + toAdd) % 7;
- return arr[indexDayToBe];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement