This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
func minCostClimbingStairs(_ cost: [Int]) -> Int { | |
var dp = [Int](repeating:0, count: cost.count+1) | |
for i in 2..<dp.count{ | |
let oneStepCost = dp[i - 1] + cost[i - 1] | |
let twoStepCost = dp[i - 2] + cost[i - 2] | |
dp[i] = min(oneStepCost, twoStepCost) | |
} | |
return dp[cost.count] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def minCostClimbingStairs(self, cost: List[int]) -> int: | |
# The array's length should be 1 longer than the length of cost | |
# This is because we can treat the "top floor" as a step to reach | |
minimum_cost = [0] * (len(cost) + 1) | |
# Start iteration from step 2, since the minimum cost of reaching | |
# step 0 and step 1 is 0 | |
for i in range(2, len(cost) + 1): | |
take_one_step = minimum_cost[i - 1] + cost[i - 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int minCostClimbingStairs(int[] cost) { | |
// The array's length should be 1 longer than the length of cost | |
// This is because we can treat the "top floor" as a step to reach | |
int minimumCost[] = new int[cost.length + 1]; | |
// Start iteration from step 2, since the minimum cost of reaching | |
// step 0 and step 1 is 0 | |
for (int i = 2; i < minimumCost.length; i++) { | |
int takeOneStep = minimumCost[i - 1] + cost[i - 1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
func loadEntityAsync() { | |
// Create an world anchor at the origin and add it to the scene | |
let anchor = AnchorEntity(world: [0,0,0]) | |
arView.scene.addAnchor(anchor) | |
let usdzPath = "path/to/usdz/asset" | |
// Load the asset asynchronously |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def maxArea(self, h: int, w: int, horizontalCuts: List[int], verticalCuts: List[int]) -> int: | |
# Start by sorting the inputs | |
horizontalCuts.sort() | |
verticalCuts.sort() | |
# Consider the edges first | |
max_height = max(horizontalCuts[0], h - horizontalCuts[-1]) | |
for i in range(1, len(horizontalCuts)): | |
# horizontalCuts[i] - horizontalCuts[i - 1] represents the distance between |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
// We will use long instead of int to prevent overflow | |
public int maxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts) { | |
// Start by sorting the inputs | |
Arrays.sort(horizontalCuts); | |
Arrays.sort(verticalCuts); | |
int n = horizontalCuts.length; | |
int m = verticalCuts.length; | |
// Consider the edges first |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Link: https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/ | |
class Solution { | |
func maxArea(_ h: Int, _ w: Int, _ horizontalCuts: [Int], _ verticalCuts: [Int]) -> Int { | |
// first sort the cuts | |
let hcuts = horizontalCuts.sorted() | |
let vcuts = verticalCuts.sorted() | |
var maxWidth:Int = 0, maxHeight:Int = 0 | |
// Find max gap b/w the vertical lines = Width |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def maxAreaOfIsland(self, grid): | |
seen = set() | |
def area(r, c): | |
if not (0 <= r < len(grid) and 0 <= c < len(grid[0]) | |
and (r, c) not in seen and grid[r][c]): | |
return 0 | |
seen.add((r, c)) | |
return (1 + area(r+1, c) + area(r-1, c) + | |
area(r, c-1) + area(r, c+1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
int[][] grid; | |
boolean[][] seen; | |
public int area(int r, int c) { | |
if (r < 0 || r >= grid.length || c < 0 || c >= grid[0].length || | |
seen[r][c] || grid[r][c] == 0) | |
return 0; | |
seen[r][c] = true; | |
return (1 + area(r+1, c) + area(r-1, c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
func maxAreaOfIsland(_ grid: [[Int]]) -> Int { | |
var maxArea = 0 , grid = grid | |
for i in 0..<grid.count{ | |
for j in 0..<grid[0].count{ | |
if grid[i][j] == 0 { | |
continue | |
} | |
let area = dfs(i,j,&grid) | |
maxArea = max(area,maxArea) |
NewerOlder