摘要: 一、题目 力扣地址:https://leetcode.cn/problems/find-first-and-last-position-of-element-in-sorted-array/description/ 二、解法思路: 也是二分查找相关题目,详细解法看注释 from typing imp 阅读全文
posted @ 2023-11-14 15:00 王寄鱼 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 一、题目 力扣地址:https://leetcode.cn/problems/search-insert-position/ 二、解法思路 与标准的二分查找一直,唯一的区别为,若所需target不在nums中,需要找到insert的索引 from typing import List class S 阅读全文
posted @ 2023-11-14 14:08 王寄鱼 阅读(8) 评论(0) 推荐(0) 编辑
摘要: 一、题目 力扣链接:https://leetcode.cn/problems/binary-search/description/ 二、解法思路 标准的二分查找题目,常规上有左闭右闭和左闭右开的解法 1、左闭右闭 class Solution: """ leetcode:704 采用左闭右闭的方式, 阅读全文
posted @ 2023-11-14 14:03 王寄鱼 阅读(10) 评论(0) 推荐(0) 编辑