My Software Engineering

My Software Engineering

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

My Software Engineering

컨텐츠 검색

태그

최근글

댓글

공지사항

아카이브

Leetcode(93)

  • 48. Rotate Image

    Description: You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. ''' [1] reverse row-by-line and transpose idea:: reverse row-by-line and transpose code:: def rotate(self, matrix: List[List[int]]..

    2021.11.03
  • 54. Spiral Matrix

    Description: Given an m x n matrix, return all elements of the matrix in spiral order. ''' [1] four-pointer) idea:: top,bottom,left,right, direction code:: (below) -T/C: O(m*n) -S/C: O(1) # except for output list ''' class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: output=[] top,bottom,left,right=0,len(matrix)-1,0,len(matrix[0])-1 dir=0 while top

    2021.11.03
  • 724. Find Pivot Index & 1991. Find the Middle Index in Array

    Description 724: Given an array of integers nums, calculate the pivot index of this array. The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right. If the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applies to the rig..

    2021.11.03
  • 79. Word Search

    Description: Given an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once. ''' [1] back-tracking - out-place) idea:: back tracking using visited_flag_matrix code:: def ex..

    2021.11.02
  • 152. Maximum Product Subarray

    Description: Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product. It is guaranteed that the answer will fit in a 32-bit integer. A subarray is a contiguous subsequence of the array. ''' [1] brute force) idea:: using two pointer(nested-loop), find max product. code:: def maxProduct(self, nums: List[int]) -> int: m..

    2021.11.02
  • 34. Find First and Last Position of Element in Sorted Array

    Description: Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. You must write an algorithm with O(log n) runtime complexity. ''' [1] linear search) idea:: 1. find target value from left to right 2-1. if there is no target value in list, return [-1,-1] 2-2. if there i..

    2021.10.30
1 ··· 5 6 7 8 9 10 11 ··· 16
티스토리
© 2018 TISTORY. All rights reserved.

티스토리툴바