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
- linked list
- 망원 밥집
- 른당사피
- two pointers
- 6월 첼린지
- prefix sum
- java
- 알고리즘
- Find the Duplicate Number
- 사당돈
- 맛집
- string
- two sum
- 발리인망원
- invert Binary Tree
- tree
- 발리 음식
- algorithm
- algorithum
- map
- 코딩 테스트
- LeetCode
- 해물감성포차
- 투포인터
- 알탕뚝배기
- Python
- findDulicate
- 코테
- 코딩 테세트
Archives
- Today
- Total
기록하는 공간
[leetcode/java] 1427.Perform String Shifts 본문
substring 함수를 이용한 풀이
class Solution {
private String takeOrtakeLast(int direction, int amount, String s) {
int strLength = s.length();
if (direction == 0) {
s = s.substring(amount, strLength) + s.substring(0 , amount);
} else {
s = (s.substring(strLength - amount, strLength) + s).substring(0, strLength);
}
return s;
}
public String stringShift(String s, int[][] shift) {
for (int i = 0; i < shift.length; i++) {
s = takeOrtakeLast(shift[i][0], shift[i][1], s);
}
return s;
}
}
'알고리즘 > leetcode' 카테고리의 다른 글
[leetcode/java] 226. Invert Binary Tree (0) | 2020.06.01 |
---|---|
[leetcode/java] 367. Valid Perfect Square (0) | 2020.05.09 |
[leetcode/java] 287. Find the Duplicate Number (0) | 2020.04.11 |
[leetcode/java]844. Backspace String Compare (0) | 2020.04.10 |
[leetcode/java] 617.Merge Two Binary Trees (0) | 2020.02.23 |
Comments