LeetCode刷题笔录Unique Paths II

STM32F407+LWIP实战:手把手教你移植mbedtls库实现Modbus TCP双向认证 本文详细介绍了如何在STM32F407微控制器上移植mbedtls库,结合LWIP协议栈实现Modbus TCP的双向认证功能。通过TLS 1.2加密通道,有效提升工业物联网通信的数据安全性,涵盖证书管理、内存优化及性能调优等关键步骤,为嵌入式系统开发者提供了一套完整的解决方案。 阅读详情

Follow up for "Unique Paths":

Now consider if some obstacles are added to the grids. How many unique paths would there be?

An obstacle and empty space is marked as 1 and 0 respectively in the grid.

For example,

There is one obstacle in the middle of a 3x3 grid as illustrated below.

[
  [0,0,0],
  [0,1,0],
  [0,0,0]
]

The total number of unique paths is 2.

Note: m and n will be at most 100.


这题比Unique Paths多了一点限制条件,因此不是一个简单的组合数的问题了。

自然的思路是动态规划。A[m][n]是到达(m,n)点得Unique Path数目。则有:

A[m][n] = 0 if obstacleGrid[m][n] = 1;

A[m][n] = A[m - 1][n] + A[m][n - 1] if obstacleGrid[m][n] = 0.

意思是如果这里有障碍,那么根本没有一条path能走到这里。如果这里没有障碍,那么可以从这个格子的上面或者左边走过来。

Base case是第一行和第一列。对于A[i][0],只要某个obstacleGrid[i][0]=1,则后面的所有A[i][0]=0.对于A[0][j]同理。

public class Solution {
    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int m = obstacleGrid.length;
        int n = obstacleGrid[0].length;
        int[][] A = new int[m][n];
        
        boolean blocked = false;
        for(int i = 0; i < m; i++){
            if(obstacleGrid[i][0] == 1){
                blocked = true;
            }
            if(blocked){
                A[i][0] = 0;
            }
            else{
                A[i][0] = 1;
            }
                
        }
        
        blocked = false;
        for(int j = 0; j < n; j++){
            if(obstacleGrid[0][j] == 1){
                blocked = true;
            }
            if(blocked){
                A[0][j] = 0;
            }
            else{
                A[0][j] = 1;
            }
        }
        
        for(int i = 1; i < m; i++){
            for(int j = 1; j < n; j++){
                if(obstacleGrid[i][j] == 1){
                    A[i][j] = 0;
                }
                else{
                    A[i][j] = A[i - 1][j] + A[i][j - 1];
                }
            }
        }
        
        return A[m - 1][n - 1];
    }
}


AMBA-CHI协议详解(七) 本节描述该协议包含的支持系统保序需求的机制。 阅读详情

相关推荐

ACPWorkbench_for_BP10

ADC支持9种采样率:8000Hz、11025Hz、12000Hz、16000Hz、22050Hz、24000Hz、32000Hz、44100Hz 以及 48000Hz。选择5种MCLK源时, 模块内部的MCLK源无效。I2S 采样率支持:8K,11.025K,12K,16K, 22.05K, 24K, 32K, 44.1K, 48K, 88.2K, 96K, 176.4K 和 192K。DAC采样率支持:8K,11.025K,12K,16K,22.05K, 24K, 32K, 44.1K和48K。

dddds222_的博客 4549

LeetCode刷题笔录 Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo

likecool21的专栏 1万+

阿里云人工智能工程师ACA认证免费课程学习笔记

阿里云人工智能工程师ACA认证免费课程学习笔记

engchina的专栏 2013

LeetCode刷题笔录 Two Sum

Two Sum Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the

likecool21的专栏 1万+

分享通达信破解交易接口的使用!

那其实通达信破解交易接口的使用方法比较复杂,这里以MA均线指标为例子,只要理解了这些操作步骤,就可以很容易地使用其他指标包括自己编写的指标来进行交易。委托结果(包含委托编号), 需要分配 1024*1024 字节的空间。委托结果数组, 每项结果需要分配 1024*1024 字节的空间。0: 买入, 1: 卖出, 2: 融资买入, 3: 融券卖出,4: (市价委托)上海五档即成剩撤, 深圳五档即成剩撤。4: 买券还券, 5: 卖券还款, 6: 现券还券。0: 上海限价委托, 深圳限价委托。

1841085904的博客 2358

QCM6490平台DDR测试:从QDUTT配置到眼图分析的实战指南

本文详细介绍了QCM6490平台DDR测试的全流程,从QDUTT工具安装配置到眼图分析,提供了实战操作指南和常见问题解决方案。通过具体案例分享,帮助工程师掌握DDR测试技巧,确保内存稳定性,特别适用于物联网和边缘计算设备的开发调试。

weixin_33910191的博客 457

LeetCode刷题笔录 Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key.Th

likecool21的专栏 6928

ENVI中Landsat8大气校正法实现地表温度精准反演

本文详细介绍了在ENVI软件中,利用大气校正法对Landsat8热红外数据进行地表温度反演的完整流程。该方法通过辐射定标、大气参数获取、发射率估算及温度转换四个核心步骤,精准剔除大气干扰,还原地表真实温度,是城市热岛效应监测、农业旱情分析等应用的关键技术。

weixin_29292535的博客 150

Stanford Algorithms学习:Clustering 2

这是紧接上面的一道题,比较有趣 Question 2 In this question your task is again to run the clustering algorithm from lecture, but on a MUCH bigger graph. So big, in fact, that the distances (i.e., edge costs

likecool21的专栏 2567

Fluent基于低氧舱气体交换仿真(氮气与空气混合)

一、背景概述 模拟低氧舱充氮气和排除混合气体的过程,假设注入95%的氮气,舱内原有气体为空气,压力为标准大气压,温度为300K。观察气体注入过程中,舱内平均氮气和氧气浓度的变化。 二、Fluent设置 Setup 1、General type选择压力基 绝对速度 瞬态 重力勾选 2、Model 能量方程开启 组分运输开启,设置方法如下: 选择后OK,view就会变成Edit,点击Edit。然后再次点击Edit。 将组分中的非氮气氧气和空气的气体移除,右边选项需要将空气放在最后一位。 3、Materi

qq_35535616的博客 1万+

RH850从0搭建Autosar开发环境【1】- 如何创建Davinci Configurator配置工程

当我们在公司接触Autosar开发环境时,基本都是完整的Davinci Configurator的配置工程,我们只能修修补补。 从本章开始将手把手搭建Rh850基于Vector公司Davinci Configurator的autosar配置工程。主要涉及到OS,COM,DCMM,NVM,BSWM,ECUM等基本模块,包括Vlink,memap使用,XCP标定的实现等。基本是实现一个基础版的项目开发。包括后期的GreenHills编译问题处理,生成最终的Hex文件。

weixin_42412049的博客 1万+

Stanford Algorithms学习:Clustering

第二周的第一个编程作业,是利用贪婪算法来实现一个clustering的问题,和ML里学的unsupervised learning差不多。 Question 1 In this programming problem and the next you'll code up the clustering algorithm from lecture for computing a

likecool21的专栏 2507

迅投miniQMT量化交易实战指南:从入门到自动化交易系统构建

迅投miniQMT量化交易实战指南摘要 本文全面介绍迅投miniQMT量化交易系统的开发流程,重点包括: 环境配置:详细说明miniQMT极简模式的安装步骤,包括xtquant库获取、Python版本要求及验证方法 行情数据模块:解析xtdata模块的核心功能,包括: 获取板块分类与股票列表 查询合约基础信息 下载历史K线数据(支持tick、分钟、日线等周期) 交易执行模块:介绍xttrader模块的交易API,涵盖: 账户连接与初始化 订单管理(下单、撤单、查询) 持仓与资产查询 实战开发:提供可直接运行

huanghm88的专栏 665

LeetCode 刷题笔录 Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link

likecool21的专栏 1806

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

LeetCode刷题笔录Edit Distance

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word:

likecool21的专栏 1296

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

LeetCode刷题笔录Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

likecool21的专栏 1109

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

LeetCode刷题笔录 Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 这题比较简单

likecool21的专栏 1043

LeetCode刷题笔录Unique Binary Search Trees

这里有个讲解(印度人口音真难懂)

likecool21的专栏 1043

LeetCode刷题笔录Container With Most Water

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin

likecool21的专栏 1001

LeetCode刷题笔录 Reverse Integer

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 随手写的一个,正常的读出每一位的数字然后反序: import java.lang.Math; public class Solution { public int revers

likecool21的专栏 941

LeetCode刷题笔录Sum Root to Leaf Numbers

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the tota

likecool21的专栏 878

LeetCode刷题笔录Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the f

likecool21的专栏 865

LeetCode刷题笔录Convert Sorted Array to Balanced Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 这题可以kan'chu'lai

likecool21的专栏 855

LeetCode 每日一题 2026/11/2-2026/11/8

记录了初步解题思路 以及本地实现代码;并不一定为最优 也希望大家能一起探讨 一起进步

AlphaTao的博客 175

LeetCode 面试经典 150_多维动态规划_交错字符串(97_C++_中等)

LeetCode 面试经典 150_多维动态规划_交错字符串(97_C++_中等) 题目描述: 给定三个字符串 s1、s2、s3,请你帮忙验证 s3 是否是由 s1 和 s2 交错 组成的。 两个字符串 s 和 t 交错 的定义与过程如下,其中每个字符串都会被分割成若干 非空 子字符串: - s = s1 + s2 + ... + sn - t = t1 + t2 + ... + tm - |n - m| <= 1 - 交错 是 s1 + t

huayimenghan的博客 205

LeetCode Hot 100 二叉树专题(二)3 题(Java)

本篇文章共 3 题:543. 二叉树的直径、102. 二叉树的层序遍历、108. 将有序数组转换为二叉搜索树。 每道题都统一按「① 题目分析 & 解题思路 → ② 常见解法(附代码)及讲解 → ③ 知识点总结」的顺序组织;代码使用 Java 编写,节点定义沿用 LeetCode 默认的 TreeNode。

2401_88612756的博客 365
上一篇: LeetCode刷题笔录Longest Consecutive Sequence
下一篇: LeetCode刷题笔录Flatten Binary Tree to Linked List
likecool21
博客等级 码龄14年 14粉丝 123原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值