반응형
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
- statement.executequery() cannot issue statements that do not produce result sets.
- xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
- JUnit
- 스프링부트테스트
- ssl이란?
- error
- Java 1.8
- No tests found for given includes
- java 11
- AWS CLI
- java version
- springboot
- OpenFeign
- aws
- log error
- java
- mac os git error
- yum install java
- java 여러개 버전
- java 버전 변경
- mysql executequery error
- Medium
- springboottest
- tls프로토콜확인
- java 1.8 11
- parse
- LeetCode
- easy
- ssl프로토콜확인
- xcrun: error: invalid active developer path
Archives
- Today
- Total
쩨이엠 개발 블로그
[ Leetcode ] 214. Shortest Palindrome - Java 본문
728x90
반응형
Given a string s, you can convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.
Example 1:
Input: s = "aacecaaa"
Output: "aaacecaaa"
Example 2:
Input: s = "abcd"
Output: "dcbabcd"
Constraints:
- 0 <= s.length <= 5 * 104
- s consists of lowercase English letters only.
Solution
class Solution {
public String shortestPalindrome(String s) {
String newString = "";
int length = s.length();
for(int i=0; i< length; i++){
newString = s.charAt(i)+newString;
}
String subString = "";
for(int i=0; i<length; i++){
subString = newString.substring(i);
if(s.startsWith(subString)){
newString = newString.substring(0, i);
break;
}
}
return newString+s;
}
}
처음으로 Hard 풀어서 신났는데 0ms에 몰려있는걸보니 내가 왜 프로그래머스 효율성이 0인지를 알겠다...
알고리즘 공부합시다...반성반성
728x90
반응형
'개발 > Programming' 카테고리의 다른 글
[ Leetcode ] 1470. Shuffle the Array - Java (0) | 2021.01.29 |
---|---|
[ Leetcode ] 1672. Richest Customer Wealth - Java (0) | 2021.01.28 |
[ Leetcode ] 162. Find Peak Element - Java (0) | 2021.01.28 |
[ Leetcode ] 1431. Kids With the Greatest Number of Candies - Java (0) | 2021.01.27 |
[ Leetcode ] 28. Implement strStr() - Java (0) | 2021.01.27 |
Comments