LeetCode刷题笔录Unique Paths

ESP32 CAM使用教程(入门级) 串口被占用,可以关闭其他使用到串口的界面;先将手机也连上wifi,然后使用手机浏览器打开这个IP地址,注意手机连接的wifi需要和开发板的wifi一致,也就是程序里自己修改的那个wifi,否则无法打开IP地址;将开发板连接到电脑,点击点击工具→端口,然后选择自己实际接的COM口,不清楚COM口的可以打开电脑设备管理器查看一下,插拔设备看看哪个COM口会刷新就是哪个COM口;安装好esp32库之后,点击工具→开发板→esp32→AI Thinker ESP32-CAM,型号要仔细找找,不要选错了; 阅读详情

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

How many possible unique paths are there?


Above is a 3 x 7 grid. How many possible unique paths are there?

Note: m and n will be at most 100.

这题大概是做LeetCode以来最简单的一道题了。注意的是Robot一开始是在左上角的格子里,而不是在棋盘外面,所以往右和往下能走的步数是m-1和n-1。

于是结果就是在m+n-2个位置里选出m-1个位置用来向右走,剩下的n-1个位置用来向下走。就是(m+n-2)!/(m-1)!(n-1)!.

直接算(m+n-2)!的话可能会溢出,所以直接算(m+n-2)!/(m-1)!,少乘几个数。

public class Solution {
    public int uniquePaths(int m, int n) {
        //the result would be (m-1+n-1)!/(m-1)!(n-1)!
        long numerator = 1;
        int bigger = m > n ? m - 1 : n - 1;
        int smaller = bigger == m - 1 ? n - 1 : m - 1;
        //divide the bigger one's factorial while calculating (m+n)!
        for(int i = m + n - 2; i > bigger; i--){
            numerator *= i;
        }
        long denominator = 1;
        for(int i = 2; i <= smaller; i++){
            denominator *= i;
        }
        return (int)(numerator / denominator);
    }
}


批处理脚本手动双击可以执行,但计划任务中执行失败 问题现象: 使用批处理脚本从linux端(samba server) 备份一些数据,设置计划任务每天凌晨两点定时备份。 1)、windows系统中映射共享文件夹为S:盘,需要输入共享用户名和密码 2)、脚本中使用xcopy命令复制共享目录中的文件到windows本地目录中。 脚本如下: set Name=%date:~0,4%%date:~5,2%%date:~8,2% chcp 65001 REM chcp防止中文乱码 mkdir "E:\脚本备份\bakscripts%Name%" xco 阅读详情

相关推荐

ChatGPT Plus完整开通指南:从账号注册到稳定使用全流程

自然语言处理(NLP)技术通过深度学习模型实现对人类语言的理解与生成,其核心原理是基于Transformer架构的大规模预训练。GPT-4作为当前最先进的生成式AI模型,在代码编写、文档分析等场景展现出显著的技术价值。在实际应用中,稳定的网络环境和合规的支付方式是确保AI助手持续服务的关键因素。针对ChatGPT Plus的开通,需要系统性地解决账号验证、虚拟信用卡支付等工程实践问题,才能实现工作流的高效整合。

weixin_34239592的博客 426

LeetCode刷题笔录Unique Paths II

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

likecool21的专栏 651

verilog CORDIC对数运算

verilog CORDIC对数运算

m0_64355812的博客 1735

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

MacOS Intel芯片实战:Docker Compose一键部署Dify全流程解析

本文详细解析了在搭载Intel芯片的MacOS系统上,使用Docker Compose一键部署开源LLM应用开发平台Dify的全流程。内容涵盖环境准备、Docker配置与镜像加速、代码拉取与配置初始化、服务启动与问题排查,以及访问验证与初步探索,旨在帮助开发者快速在本地搭建私有化AI应用开发环境。

ik678901234的博客 618

WRF后处理避坑指南:从namelist配置到降水计算的全流程解析

本文提供了一份详尽的WRF模式后处理避坑指南,涵盖从理解wrfout文件结构、核心变量解析到累计降水计算与专业气象图绘制的全流程。重点解析了RAINC与RAINNC的正确处理方法,并分享了使用wrf-python库高效绘制位势高度叠加风场图、累计降水图等专业图表的实战技巧与代码,旨在帮助用户规避常见错误,提升后处理效率与图表质量。

weixin_29200485的博客 353

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

Unity 第一人称视角控制移动、旋转

第一人称视角操作此功能主要是借鉴YouTube,写的蛮好我就搬运过来让大家也试试。

qq_36515472的博客 4201

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

【OpenClaw企业级智能体实战】第27篇:Skill生态运营——企业私有Skill商店的搭建与审核机制

2026年ClawHavoc供应链攻击事件曝光超1200个恶意Skill渗透公共技能市场,工信部明确要求企业审慎使用第三方技能包并严格审查代码。本文基于真实安全事件与行业实践,完整讲解企业私有Skill商店从0到1搭建方案,覆盖小团队极简GitLab私有仓库、中大型企业Nacos 3.2私有Registry两种主流架构,配套企业级安全审核四步法、静态代码扫描规则、CI/CD自动化审计、数字签名校验与版本生命周期管理。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 499

【STK】手把手教你利用STK进行导弹和反导仿真02 - STK/MMT模块01 导弹任务分析工具概述

种工具:导弹设计工具(Missile Design Tool,MDT )、导弹飞行工具(Missile Flight Tool,截弹,或者用内置拦截弹编辑器创建的个性化的拦截弹, IFT 能够对 ―一对一 ‖动能拦截。导设置系统参数, 并对其有效性进行验证, 画性能图,保证该设计是可行的。(SAIC)公司联合开发研制,极大扩展了 STK 原有的导弹对象的功能,能够精确仿真。IFT 能够对拦截飞机、 导弹、卫星等目标进行仿真和分析。(2)推进系统参数,包括推力,比冲,秒流量,推力持续时间,喷嘴出口面积,

weixin_44184852的博客 1876

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

使用VNA(Vector Network Analyzer)对S参数进行去嵌(二)

无论是使用 EM 仿真工具创建的简化模型(如一段理想传输线)还是复杂模型用于测试夹具,现在都需要使用该 S 参数模型执行去嵌入过程。

小孟同学的博客 6108

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

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

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

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

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

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 Rotate Image
下一篇: LeetCode刷题笔录Binary Tree Level Order Traversal II
likecool21
博客等级 码龄14年 14粉丝 123原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值