강의로 돌아가기
코딩

테스트케이스 14번이 계속 틀립니다

14번 반례를 알 수 있을까요..?

작성중인 코드―Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

class Solution {
    public String solution(String video_len, String pos, String op_start, String op_end, String[] commands) {

        DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("HH:mm:ss");
        LocalTime start = LocalTime.parse(("00:"+op_start),timeFormat);
        LocalTime end = LocalTime.parse(("00:"+op_end), timeFormat);
        LocalTime len = LocalTime.parse(("00:"+video_len), timeFormat);
        LocalTime now = LocalTime.parse(("00:"+pos), timeFormat);    

        LocalTime zero = LocalTime.parse(("00:00:00"), timeFormat);  
        //opening check
        if( now.equals(start) || (now.isBefore(end) && now.isAfter(start))) {
            now = end;
        }

         for(int i = 0 ; i < commands.length; i++) {

            //System.out.println( "1111:"+now);
            if(commands[i].equals("prev")) {


                if(now.getMinute() == 0 && now.getSecond() <10) {
                    now = zero;
               } else {
                    now = now.minusSeconds(10L);
                }
              //  System.out.println( "prev:"+now);

            } else {
                now = now.plusSeconds(10);
           //     System.out.println( "next:"+now);



            }

           // System.out.println( "22222:"+now);

            //opening check
            if( now.equals(start) || (now.isBefore(end) && now.isAfter(start))) {
                now = end;
          //      System.out.println( "33333:"+now);
            }
            if(now.isAfter(len)) {
                now = len;
           //     System.out.println( "4444444:"+now);

            }

        }
        String resultm = String.valueOf(now.getMinute());
        String results = String.valueOf(now.getSecond());

       if(resultm.length() <2) {
           resultm = "0"+resultm;
       } 
       if(results.length() == 0) {
           results = ":00";
       } else if(results.length() <2) {
           results = results+ "0";
       }

        return resultm + ":"+results;

    }
}

1 개의 답변
낙방여우

반례입니다.
입력값 〉 "30:00", "00:08", "00:00", "00:05", ["prev"]
기댓값 〉 "00:05"

답변 쓰기
이 입력폼은 마크다운 문법을 지원합니다.