본문 바로가기

분류 전체보기351

[leetcode 8] String to Integer (atoi) Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after.. 2020. 11. 15.
[leetcode 7] Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Note: Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows. Example 1: Input: x = 123 Output: 321 Example 2: Input: x = -123 Output: -321 Example 3: Input:.. 2020. 11. 15.
[leetcode 387] First Unique Character in a String Given a string, find the first non-repeating character in it and return its index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode" return 2. 문제 풀이: 해쉬맵 사용. 문자열 전체를 돌면서 카운트 진행 카운트가 처음으로 1이 나오는 문자열 인덱스를 리턴 class Solution { public int firstUniqChar(String s) { int result = -1; int[] count = new int[26]; for(int i=0; i 2020. 11. 14.
[leetcode 395] Longest Substring with At Least K Repeating Characters Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times. 문자열이 최소 k번 등장하는 가장 긴 부분 문자열 찾기 Example 1: Input: s = "aaabb", k = 3 Output: 3 The longest substring is "aaa", as 'a' is repeated 3 times. Example 2: Input: s = "ababbc", k = 2 Output: 5 The longest substring is "ababb", as 'a' is repeated .. 2020. 11. 14.