接外包,有相关需求的可以联系我:Telegram | Email

Koko Eating Bananas | Binary Search


Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours. Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any ......

Find First and Last Position of Element in Sorted Array | Binary Search


Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return[-1, -1]. You must write an algorithm with O(log n) runtime complexity. https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array......

Binary Search


Description Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an algorithm with O(log n) runtime complexity. https://leetcode.com/problems/binary-search/ Code submit code class Solution: def search(self, nums: L......

Longest Substring Without Repeating Characters | Sliding Windows


Descreption Given a string s, find the length of the longest substring without repeating characters. https://leetcode.com/problems/longest-substring-without-repeating-characters/ Solution sliding windows, The most import things is how to get The max. Code submit code class Solution: def lengthOfLongestSubstring(self, ......

Find All Anagrams in a String | Sliding Windows


Desciption Given two strings s and p, return an array of all the start indices of p\'s anagrams in s. You may return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Input: s = "cbaebabacd", p = "abc" Output: [0,6] Explanation: The ......

Minimum Window Substring


Description Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "". The testcases will be generated such that the answer is unique. A substring is a contiguous sequence of characters with......

Permutation in String


Desciption Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1's permutations is the substring of s2. Input: s1 = "ab", s2 = "eidbaooo" Output: true Explanation: s2 contains one permutation of s1 ("ba"). https://leetcode.com/problems/permutation-in-string/ Thought Slide Win......

Reverse String


Desciption Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place with O(1) extra memory. Thought Two Pointer Code class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ # s.......

两数之和 II - 输入有序数组


描述 给你一个下标从 1 开始的整数数组 numbers ,该数组已按 非递减顺序排列 ,请你从数组中找出满足相加之和等于目标数 target 的两个数。如果设这两个数分别是 numbers[index1] 和 numbers[index2] ,则 1 <= index1 < index2 <= numbers.length 。 以长度为 2 的整数数组 [index1, index2] 的形式返回这两个整数的下标 index1 和 index2。 你可以假设每个输入 只对应唯一的答案 ......

删除链表的倒数第 N 个结点 | 双指针


描述 给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点。 https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/ 思路 双指针技巧,快慢指针。 Code 提交Code # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def......


微信公众号

👉 NewsLetter ❤️ 邮箱订阅 👈

优惠码