LeetCode刷题笔录Unique Paths II

大模型LLM部署方式 建议根据实际需求选择方案,企业级服务优先考虑vLLM或TGI,个人用户可尝试Ollama或Hugging Face本地加载。若需完整代码示例,可参考网页2的VLLM实战或网页5的TGI部署案例。:高并发、低延迟的API服务,需分布式推理支持。:快速创建可分享的Web应用。:个人开发、快速原型验证。 阅读详情

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];
    }
}


银河麒麟桌面系统批量交付:封装自动化ISO镜像,百台装机效率提升10倍 麒麟桌面系统自动化ISO镜像定制摘要 本文详细介绍麒麟桌面版ISO安装镜像的定制方法,通过修改系统文件实现自动化安装部署。主要内容包括:1) 挂载原版ISO并提取文件;2) 使用unsquashfs解压系统文件进行定制化修改,包括添加系统标记配置;3) 配置ky-installer.cfg自动应答文件,设置安装参数如用户名、密码、分区方案等;4) 修改grub引导配置启用自动安装模式。该流程支持磁盘加密、自定义分区、自动登录等功能,生成的定制镜像可满足批量部署需求,显著提升系统安装效率。 阅读详情

相关推荐

注册“Oracle Provider for OLE DB”和创建链接服务器

注册“Oracle Provider for OLE DB”和创建链接服务器 在sql server 数据库上创建链接服务器,连接oracle数据库,访问接口需要设置为:“Oracle Provider for OLE DB”。 如果电脑上没有这个驱动,安装一个完整的Oracle11gR2程序是一个有效的方法,但这个64位版本的安装包有2个多G, 相当庞大,如果仅仅...

weixin_30760895的博客 2383

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万+

SystemC实战:用C++搞芯片建模的5个典型场景(含代码示例)

本文通过五个典型实战场景,详细介绍了如何使用SystemC这一基于C++的硬件建模库进行芯片设计与系统级建模。内容涵盖从基础并发模块构建、事务级总线建模、跨时钟域验证,到与ModelSim协同仿真及多核系统性能探索,并提供了完整的代码示例,帮助软件工程师利用熟悉的C++工具链高效参与硬件架构设计与验证。

weixin_29191761的博客 314

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万+

华为2288H V5服务器断电后‘趴窝’?别慌,手把手教你用SmartKit+BMC修复工具搞定

本文详细介绍了华为2288H V5服务器在断电后无法启动的修复方法,通过SmartKit和BMC修复工具进行故障诊断与修复。文章提供了从工具获取、安装到具体修复流程的完整指南,帮助运维人员快速恢复服务器运行,并给出了后续加固与预防措施,确保服务器稳定运行。

weixin_30575517的博客 297

2.1 量子精密测量:SERF原子陀螺仪中的核自旋-电子自旋强耦合机制

本文深入解析了SERF原子陀螺仪中核自旋-电子自旋强耦合机制的核心原理与应用。通过量子精密测量技术,SERF陀螺仪实现了超高精度的惯性导航,其独特的磁场自补偿和拉莫尔进动特性使其在弱磁场环境下表现出色。文章还探讨了关键技术突破和前沿进展,展示了量子精密测量在惯性导航领域的巨大潜力。

kotlin6android的博客 210

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

ESP32搭配FT6236触摸屏:从芯片手册到完整I2C驱动代码的保姆级解析

本文详细解析了ESP32搭配FT6236触摸屏的I2C驱动开发过程,从芯片手册解读到完整代码实现。通过硬件架构分析、寄存器配置、I2C通信封装及触摸数据处理等步骤,提供了一套完整的驱动解决方案,帮助开发者快速掌握ESP32与触摸屏的交互技术。

weixin_29174385的博客 291

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

RK3588 Buildroot 新建板级DTS

在rk3588 linux开发过程中,新创建板型主要基于硬件差异化、软件适配与优化、项目定制化等多方面需求。

501846585_QQAndroid_java 1298

Spring Boot 与 Redisson 版本适配深度解析

Spring Boot 与 Redisson 的版本适配是一个动态演进的过程。开发者需要密切关注两者官方的版本更新日志,建立完善的版本验证机制。本文提供的适配方案基于当前最新技术状态(2024年1月),建议在实际生产环境中通过灰度发布策略验证版本兼容性。只有深入理解底层技术原理,才能在分布式系统的星辰大海中稳健航行。延伸阅读Spring Boot 官方迁移指南。

fudaihb的博客 1081

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

电子元器件-三极管终终篇:三极管工作原理详解、参数/手册详解、开关应用详解、Ib电流研究、开关应用实例

三极管工作原理与应用摘要 三极管是一种电流控制器件,通过小基极电流控制大集电极电流。其内部结构由高掺杂发射区、薄低掺杂基区和中等掺杂集电区组成,形成NPN或PNP结。三极管有三种工作状态: 截止区:发射结和集电结均反偏,无放大作用 放大区:发射结正偏,集电结反偏,Ic=βIb 饱和区:两结均正偏,Ic不再随Ib增大 作为开关使用时,需确保三极管深度饱和(Vce≈0.2V)。设计要点包括: 基极电阻计算确保Ib足够大 集电极电阻控制Ic 基极加下拉电阻提高抗干扰 NPN管作地开关,PNP管作电源开关 典型应用

qq_60226558的博客 311

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

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

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

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

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

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

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

求集合的交集/差集

先利用外部排序使两个磁盘文件有序,然后顺序读取两个文件,使用双指针求交集。在进阶 1 中,我们是通过双指针去做的,最坏情况下我们需要完整遍历。时,O(n log m) 可能明显优于 O(n + m)。的,这就使得我们可以通过从 1~1000 遍历来确定交集。,它们已经按非降序排序,请你返回两个数组的。和上一题的区别在于,这里需要找到重复的元素。返回一个数组,数组中的每个元素在。的每个字符串中都出现的共用字符(**注意:**列表中的整数可以按。较小,可以完整加载到内存,而。正整数组成的一个非空数组,按。

jyyyyx的算法之旅 112

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

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

2401_88612756的博客 365

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刷题笔录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、付费专栏及课程。

余额充值