개발/알고리즘
-
리트코드 6번: Zigzag Conversion개발/알고리즘 2024. 3. 24. 18:24
문제 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) (주어진 문자열을 주어진 로우 수만큼 지그재그 형태로 만든 후 첫번째 라인부터 왼쪽에서 오른쪽으로 읽은 값을 출력하기) P A H N A P L S I I G Y I R And then read line by line: "PAHNAPLSIIGYIR" 예제 Input: s = "PAYPALISHIRING", numRows = 4 Output: "PINALSIGYAHRPI" P I N A L S I..
-
리트코드 5번: Longest Palindromic Substring개발/알고리즘 2024. 2. 29. 00:29
문제 Given a string s, return the longest palindromic substring in s. (앞에서부터 읽어도 뒤에서부터 읽어도 같은 문자열 중 가장 긴 문자열 찾기) 예시 Input: s = "babad" Output: "bab" Explanation: "aba" is also a valid answer. Input: s = "cbbd" Output: "bb" 내 풀이 내 생각의 흐름 1. 음... 모르겠다 2. 힌트를 보자. https://youtu.be/UflHuQj6MVA 영상을 보고 깨달음을 얻음 3. 후다닥 구현 /** * @param {string} s * @return {string} */ var longestPalindrome = function (s) { ..
-
리트코드 3번: Longest Substring Without Repeating Characters개발/알고리즘 2024. 2. 27. 00:41
문제 Given a string s, find the length of the longest substring without repeating characters. 예시 Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Input: s = "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Notice that the answer must be a substring, "p..