-
Notifications
You must be signed in to change notification settings - Fork 0
[0512] Programmers_lee #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jiyeon-agnes-lee
wants to merge
2
commits into
main
Choose a base branch
from
0512/lee/pro
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| class Solution { | ||
| public int solution(int[] absolutes, boolean[] signs) { | ||
| int answer = 0; | ||
| for(int i = 0; i < absolutes.length; i++) { | ||
| if(signs[i]) | ||
| answer += absolutes[i]; | ||
| else | ||
| answer -= absolutes[i]; | ||
| } | ||
| return answer; | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| class Solution { | ||
| static String answer; | ||
| static int ansTime; | ||
|
|
||
| public String solution(String m, String[] musicinfos) { | ||
| // 네오가 찾으려는 음악의 제목 | ||
| answer = ""; | ||
| // 네오가 찾으려는 음악의 재생 시간 | ||
| ansTime = 0; | ||
| // 네오가 기억한 멜로디를 확인할 문자열 만들기용 | ||
| StringBuilder sb = new StringBuilder(); | ||
| // 해당 음악 존재 여부 판단 | ||
| boolean flag = false; | ||
| for (int i = 0; i < musicinfos.length; i++) { | ||
| String[] info = musicinfos[i].split(","); | ||
| int time = calcTime(info[0], info[1]); // 걸린 시간 구하기 | ||
| int t = time; // 반복문 조건용 | ||
| int idx = 0; // 문자열의 인덱스 | ||
| int len = info[3].length(); // 음악의 길이 | ||
| // 시간 동안 재생되는 음악의 형태 | ||
| while (t != 0) { | ||
| // 음악의 길이까지 다 돌았으면 다시 처음부터 | ||
| if (idx == len) | ||
| idx = 0; | ||
| // 문자열에 음악의 현재 인덱스 번호 문자 + | ||
| sb.append(info[3].charAt(idx++)); | ||
| // 다시 한번 인덱스 확인 | ||
| if (idx == len) | ||
| idx = 0; | ||
| // 뒤 인덱스가 #인 경우 붙여주기 | ||
| if (info[3].charAt(idx) == '#') | ||
| sb.append(info[3].charAt(idx++)); | ||
| // 시간 1분 소요 | ||
| t--; | ||
| } | ||
| // 현재 만들어진 문자열 | ||
| String str = sb.toString(); | ||
| // contains를 사용하기 위해 m에 #이 붙은 경우를 고려 | ||
| // "" 로 없애면, 뒤 문자와 합쳐지면서 m이 생겨날 수 있으므로, | ||
| // 쓰이지 않는 H로 변경 | ||
| str = str.replace(m+"#", "H"); | ||
| // m 멜로디가 포함되어있는지 확인 | ||
| if (str.contains(m)){ | ||
| // 포함되어있으면, 갱신 | ||
| updateAns(time, info[2]); | ||
| flag = true; | ||
| } | ||
| sb.setLength(0); // 초기화 | ||
| } | ||
| // 해당하는 음악 없을 때 출력, | ||
| if(!flag) | ||
| answer = "(None)"; | ||
| return answer; | ||
| } | ||
| // 시간 구하기 ( 분 ) | ||
| private int calcTime(String st, String ed) { | ||
| int time = 0; | ||
| String[] timeInfo = st.split(":"); | ||
| int stH = Integer.parseInt(timeInfo[0]); | ||
| int stM = Integer.parseInt(timeInfo[1]); | ||
| timeInfo = ed.split(":"); | ||
| int edH = Integer.parseInt(timeInfo[0]); | ||
| int edM = Integer.parseInt(timeInfo[1]); | ||
| if (stM <= edM) { | ||
| time += (edM - stM) + (edH - stH) * 60; | ||
| } else { | ||
| stH += 1; | ||
| time += edM + (60 - stM) + (edH - stH) * 60; | ||
| } | ||
| return time; | ||
| } | ||
| // 값 갱신하기 | ||
| private void updateAns(int currTime, String title) { | ||
| // 현재까지의 해당하는 음악 중 재생시간이 가장 긴 것과 이번 음악의 재생시간 비교하여, | ||
| // 더 긴 것으로 갱신 ( 같으면 먼저 입력한 것 이므로 갱신 X) | ||
| if (currTime > ansTime) { | ||
| answer = title; | ||
| ansTime = currTime; | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
괄호가 없어서 좋아요