You are given an m x n binary matrix grid. An island is a group of 1‘s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. The area of an island is the number of cells with a value 1 in the island. Return the maximum area of an island in grid. If there is no island, return 0. …
Category Archives: leetcode
Leetcode 31: Next Permutation
31. Next Permutation Total Accepted: 87393 Total Submissions: 313398 Difficulty: Medium Contributors: Admin Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The replacement must be in-place, do not allocate …
Leetcode 64: Minimum Path Sum
https://leetcode.com/problems/minimum-path-sum/ 64. Minimum Path Sum Total Accepted: 91005 Total Submissions: 247256 Difficulty: Medium Contributors: Admin Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any …
Leetcode 88: Merge Sorted Array
88. Merge Sorted Array Total Accepted: 129487 Total Submissions: 416385 Difficulty: Easy Contributors: Admin Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The …
Leetcode 77: Combinations
77. Combinations Total Accepted: 96007 Total Submissions: 258054 Difficulty: Medium Contributors: Admin Given two integers n and k, return all possible combinations of k numbers out of 1 … n. For example,If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] Code class …
Leetcode 254: Factor Combinations
254. Factor Combinations Total Accepted: 16019 Total Submissions: 40853 Difficulty: Medium Contributors: Admin Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a function that takes an integer n and return all possible combinations of its factors. Note: You may assume …
Leetcode 221: Maximal Square
https://leetcode.com/problems/maximal-square/ 221. Maximal Square Total Accepted: 44584 Total Submissions: 169331 Difficulty: Medium Contributors: Admin Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 …
Leetcode 211: Add and Search Word – Data structure design
211. Add and Search Word – Data structure design Total Accepted: 37880 Total Submissions: 188966 Difficulty: Medium Contributors: Admin Design a data structure that supports the following two operations: void addWord(word) bool search(word) search(word) can search a literal word or a regular expression string containing only letters a-z or .. A . means it can …
Continue reading “Leetcode 211: Add and Search Word – Data structure design”
Leetcode 252: Meeting Rooms
https://leetcode.com/problems/meeting-rooms/ 252. Meeting Rooms Total Accepted: 19160 Total Submissions: 43021 Difficulty: Easy Contributors: Admin Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],…] (si < ei), determine if a person could attend all meetings. For example,Given [[0, 30],[5, 10],[15, 20]],return false. Code # Definition for an interval. # …
Leetcode 3466: Moving Average from Data Stream
346. Moving Average from Data Stream Total Accepted: 11701 Total Submissions: 20717 Difficulty: Easy Contributors: Admin Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. For example, MovingAverage m = new MovingAverage(3); m.next(1) = 1 m.next(10) = (1 + 10) / 2 m.next(3) = …
Continue reading “Leetcode 3466: Moving Average from Data Stream”