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
- java
- Stack
- Counting
- Method
- 구현
- simulation
- 자바
- 코딩테스트
- dynamic programming
- Matrix
- Class
- SQL
- implement
- greedy
- string
- Data Structure
- Tree
- Binary Tree
- Number Theory
- 파이썬
- database
- geometry
- sorting
- Math
- hash table
- Binary Search
- 코테
- two pointers
- array
- bit manipulation
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 796. Rotate String 본문
1. Input
1) 문자열 s
2) 문자열 goal
2. Output
1) s의 문자열을 왼쪽으로 밀어서 goal과 같은 문자열을 만들 수 있으면 true, 아니면 false를 반환
3. Constraint
1) 1 <= s.length, goal.length <= 100
2) s와 goal은 영어 소문자로만 이루어져 있다.
4. Example
Input: s = "abcde", goal = "cdeab" -> Output: true
설명: abcde -> bcdea -> cdeab
shift 2번만에 s가 goal과 같아졌으므로 true를 반환한다.
5. Code
1) 첫 코드(2022/07/13)
if(s.length()!=goal.length())
return false;
for(int i=0 ; i<s.length() ; i++)
if(s.charAt(i)==goal.charAt(0)){
if(s.substring(i,s.length()).equals(goal.substring(0,s.length()-i))){
s = s.substring(i,s.length()) + s.substring(0,i);
break;
}
}
return s.equals(goal);
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 806. Number of Lines To Write String (0) | 2022.12.07 |
---|---|
[LeetCode/Easy] 804. Unique Morse Code Words (0) | 2022.12.07 |
[LeetCode/Easy] 771. Jewels and Stones (0) | 2022.12.07 |
[LeetCode/Easy] 762. Prime Number of Set Bits in Binary Representation (0) | 2022.12.07 |
[LeetCode/Easy] 747. Largest Number At Least Twice of Others (0) | 2022.12.07 |