반응형
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
- Medium
- error
- mac os git error
- aws
- Java 1.8
- java
- OpenFeign
- parse
- java 1.8 11
- java 여러개 버전
- JUnit
- easy
- java version
- springboottest
- ssl프로토콜확인
- xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
- ssl이란?
- tls프로토콜확인
- mysql executequery error
- log error
- java 11
- springboot
- statement.executequery() cannot issue statements that do not produce result sets.
- No tests found for given includes
- LeetCode
- yum install java
- 스프링부트테스트
- xcrun: error: invalid active developer path
- AWS CLI
- java 버전 변경
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