[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์์ด ๋๋ง์๊ธฐ (์๋ฐ java)
1. ๋ฌธ์ : https://school.programmers.co.kr/learn/courses/30/lessons/12981?language=java
2. ํ์ด
3. ์ฝ๋
class Solution {
public int[] solution(int n, String[] words) {
int[] answer = {0,0};
int temp1 = 0;
for(int i=1;i<words.length;i++){
String word = words[i];
String prev = words[i-1];
int plen = prev.length()-1;
if(word.charAt(0) != prev.charAt(plen)){
temp1 = i+1;
break;
}
boolean check = false;
for(int j = 0;j<i;j++){
if(word.equals(words[j])){
temp1 = i+1;
check = true;
break;
}
}
if(check == true) break;
}
if(temp1 == 0) return answer;
int first = temp1%n;
int second = temp1/n;
answer[0] = first == 0? n:first;
answer[1] = first == 0? second:second+1;
return answer;
}
}
'๐ป Coding Problems Solving > Array | String | Loop' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์ฐ์ ๋ถ๋ถ ์์ด ํฉ์ ๊ฐ์ (์๋ฐ java) (0) | 2023.02.27 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ๊ทค ๊ณ ๋ฅด๊ธฐ (์๋ฐ java) (0) | 2023.02.22 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์ซ์์ ํํ (์๋ฐ java) (0) | 2022.11.26 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์ด์ง๋ณํ๋ฐ๋ณตํ๊ธฐ (์๋ฐ java) (0) | 2022.11.26 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ๋ฌธ์์ด ๋ง๋ค๊ธฐ (์๋ฐ java) (0) | 2022.11.24 |
์ต๊ทผ๋๊ธ