Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- array
- Binary Tree
- implement
- Math
- SQL
- two pointers
- 구현
- simulation
- Data Structure
- 자바
- java
- Class
- Method
- hash table
- Tree
- Binary Search
- sorting
- geometry
- bit manipulation
- 코테
- 파이썬
- string
- Matrix
- greedy
- 코딩테스트
- Counting
- database
- dynamic programming
- Stack
- Number Theory
Archives
- Today
- Total
코린이의 소소한 공부노트
[프로그래머스/Lv.0] 문자열 밀기 본문
1. Input
1) 문자열 A
2) 문자열 B
2. Output
A를 오른쪽으로 한 칸씩 밀었을 때
1) B가 될 수 있다면 밀어야 하는 횟수 반환
2) B가 될 수 없다면 –1을 반환
3. Constraint
1) 0 < A의 길이 = B의 길이 < 100
2) A, B는 알파벳 소문자로 이루어져 있다.
4. Example
Input: A=“hello”,B=“ohell” -> Output: 1
Input: A=“hello”,B=“ehllo” -> Output: -1
5. Code
1) 첫 코드(2022/11/03)
if(A.equals(B))
return 0;
int answer = -1;
for(int i=0 ; i<B.length() ; i++){
char c = B.charAt(i);
if(A.charAt(0)==c){
String b = B.substring(i,B.length()) + B.substring(0,i);
if(A.equals(b)){
answer = i;
break;
}
} // if(A.charAt(0)==c)
} // for i
return answer;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[프로그래머스/Lv.0] A로 B 만들기 (0) | 2022.11.09 |
---|---|
[프로그래머스/Lv.0] 이진수 더하기 (0) | 2022.11.09 |
[프로그래머스/Lv.0] 유한소수 판별하기 (0) | 2022.11.09 |
[프로그래머스/Lv.0] 평행 (0) | 2022.11.09 |
[프로그래머스/Lv.0] 삼각형의 완성조건 (2) (0) | 2022.11.09 |