My Software Engineering

My Software Engineering

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

My Software Engineering

컨텐츠 검색

태그

최근글

댓글

공지사항

아카이브

Leetcode(93)

  • 162. Find Peak Element

    Description: A peak element is an element that is strictly greater than its neighbors. Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks. You may imagine that nums[-1] = nums[n] = -∞. You must write an algorithm that runs in O(log n) time. ''' [1] linear search - Time Limit Exceeded) idea:: find peak..

    2021.10.27
  • 75. Sort Colors

    Description: Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively. You must solve this problem without using the library's sort function. ''' [1] using library function) -T/C..

    2021.10.27
  • 234. Palindrome Linked List

    Description: Given the head of a singly linked list, return true if it is a palindrome. # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next ''' [1] using list) idea:: while traversal from head, push value in list(). by reversing list, check list' value and linked list' value. code:: def isPalindrome(self, head: Option..

    2021.10.27
  • 9. Palindrome Number

    Description: Given an integer x, return true if x is palindrome integer. An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not. ''' [1] math solution) code:: def isPalindrome(self, x: int) -> bool: if x0: dst=dst*10+(x%10) x//=10 return src==dst -T/C: O(log(x)) -S/C: O(1) ''' ''' [2] using str() ) idea:: integer x -> str(x) and rev..

    2021.10.27
  • 268. Missing Number

    Description: Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. ''' [1] two pass) idea:: [0,n] -> exclusive XOR -> ans ans-> for num in nums: ans^=num -> ans -T/C: O(n+1 + n) =O(2n) =O(n) -S/C: O(1) ''' ''' [2] one pass) idea:: while XOR operation in nums, also do XOR opeartion j. after loop, ans^=j. then ret..

    2021.10.27
  • 338. Counting Bits

    Description: Given an integer n, return an array ans of length n + 1 such that for each i (0

    2021.10.27
1 ··· 7 8 9 10 11 12 13 ··· 16
티스토리
© 2018 TISTORY. All rights reserved.

티스토리툴바