노트/Algorithm : 알고리즘(63)
-
[leetcode] 9. Palindrome Number
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Follow up: Could you solve it without converting the integer to a string? 1. str 으로 바꿔서 한글자씩 분리해서 푸는 방법 class Solution(object): def isPalindrome(self, x): """ :type x: int :rtype: bool """ if -pow(2,31)
2020.11.11 -
[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. 1. str 으로 바꿔서 한글자씩 분리해서 푸는 방법 class Solution(object): def reverse(self, x): """ :type x: int :r..
2020.11.11 -
[leetcode] 3. Longest Substring Without Repeating Characters
3. Longest Substring Without Repeating Characters Given a string s, find the length of the longest substring without repeating characters. 방법1 NO_OF_CHARS = 256 class Solution: def lengthOfLongestSubstring(self,s): """ :type s: str :rtype: int """ # 마지막 인덱스 array를 -1로 초기화 lastIndex = [-1] * NO_OF_CHARS n = len(s) res = 0 i = 0 for j in range(0,n): # str[j]의 마지막 인덱스를 찾아서 +1을 하고 # 현재 i 값과 last의 최댓..
2020.11.02