[LeetCode] 3105. Longest Strictly Increasing or Strictly Decreasing Subarray (Python)
·
알고리즘/LeetCode
난이도: Easy문제 설명You are given an array of integers nums. Return the length of the longest subarray of nums which is either strictly increasing or strictly decreasing. 문제 예제Example 1:Input: nums = [1,4,3,3,2]Output: 2Explanation:The strictly increasing subarrays of nums are [1], [2], [3], [3], [4], and [1,4].The strictly decreasing subarrays of nums are [1], [2], [3], [3], [4], [3,2], and [4,3].Hen..
[LeetCode] 1752. Check if Array Is Sorted and Rotated (Python)
·
알고리즘/LeetCode
난이도: Easy문제 설명Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false. There may be duplicates in the original array. Note: An array A rotated by x positions results in an array B of the same length such that A[i] == B[(i+x) % A.length], where % is the modulo operation. 문제 예제Examp..
[LeetCode] 3151. Special Array I (Python)
·
알고리즘/LeetCode
난이도: Easy문제 설명An array is considered special if every pair of its adjacent elements contains two numbers with different parity. You are given an array of integers nums. Return true if nums is a special array, otherwise, return false. 문제 예제Example 1:Input: nums = [1]Output: trueExplanation:There is only one element. So the answer is true.Example 2:Input: nums = [2,1,4]Output: trueExplanation:Ther..
[LeetCode] 827. Making A Large Island (Python)
·
알고리즘/LeetCode
난이도: Hard문제 설명You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applying this operation. An island is a 4-directionally connected group of 1s. 문제 예제Example 1:Input: grid = [[1,0],[0,1]] Output: 3 Explanation: Change one 0 to 1 and connect two 1s, then we get an island with area = 3. Example 2:Input: gri..
[LeetCode] 785. Is Graph Bipartite? (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in graph[u], there is an undirected edge between node u and node v. The graph has the following properties:There are no self-edges (graph[u] does not contain u).There a..
[LeetCode] 2658. Maximum Number of Fish in a Grid (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents:A land cell if grid[r][c] = 0, orA water cell containing grid[r][c] fish, if grid[r][c] > 0.A fisher can start at any water cell (r, c) and can do the following operations any number of times:Catch all the fish at cell (r, c), orMove to any adjacent water cell.Return the maximum number of fish the fis..