My Software Engineering

My Software Engineering

  • 분류 전체보기 (94)
    • Leetcode (93)
  • 홈
  • Leetcode
RSS 피드
로그인
로그아웃 글쓰기 관리

My Software Engineering

컨텐츠 검색

태그

최근글

댓글

공지사항

아카이브

Leetcode(93)

  • 647. Palindromic Substrings

    Description: Given a string s, return the number of palindromic substrings in it. A string is a palindrome when it reads the same backward as forward. A substring is a contiguous sequence of characters within the string. ''' [1] brute force) code:: def countSubstrings(self, s: str) -> int: count=0 for i in range(len(s)): for j in range(i,len(s)+1): if s[i:j]!="" and self.isPalindrome(s[i:j]): co..

    2021.11.08
  • 43. Multiply Strings

    Description: Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Note: You must not use any built-in BigInteger library or convert the inputs to integer directly. ''' [1] brute force) idea:: ex. '456'=10^2*4 + 10^1*5 + 10^0*6 '123'=10^2*1 + 10^1*2 + 10^0*3 so, by using nested loop. multiply each digit by digit a..

    2021.11.07
  • 20. Valid Parentheses

    Description: Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. ''' [1] using stack) code:: (below) -T/C: O(n) -S/C: O(n) ''' class Solution: def isValid(self, s: str) -> bool: stack=[] for..

    2021.11.07
  • 125. Valid Palindrome

    Description: A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers. Given a string s, return true if it is a palindrome, or false otherwise. ''' [1] two pointer) code:: def isPalindrome(self, s: str) -> bool: left,right=0,l..

    2021.11.07
  • 242. Valid Anagram

    Description: Given two strings s and t, return true if t is an anagram of s, and false otherwise. ''' [1] sort) idea:: 1. sort both s and t 2. check s[i]==t[i] code:: def isAnagram(self, s: str, t: str) -> bool: if len(s)!=len(t): return False s_list=sorted(s) t_list=sorted(t) for i in range(len(s_list)): if s_list[i]!=t_list[i]: return False return True -T/C: O(nlogn + mlogm) # n==len(s), m==le..

    2021.11.06
  • 41. First Missing Positive

    Description: Given an unsorted integer array nums, return the smallest missing positive integer. You must implement an algorithm that runs in O(n) time and uses constant extra space. ''' [1] brute force) idea:: if len(nums)==n, then 10: hashmap[num]+=1 for i in range(1,len(hashmap)): if hashmap[i]==0: return i return -1 -T/C: O(n) -S/C: O(n) ''' ''' [4] hashmap & sorting - in-place) code:: (belo..

    2021.11.06
1 ··· 3 4 5 6 7 8 9 ··· 16
티스토리
© 2018 TISTORY. All rights reserved.

티스토리툴바