mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
leetcode problem
This commit is contained in:
parent
6977cdaf29
commit
a854521dcb
@ -2,17 +2,16 @@
|
|||||||
Problem: Find First and Last Position of Element in Sorted Array
|
Problem: Find First and Last Position of Element in Sorted Array
|
||||||
|
|
||||||
Description:
|
Description:
|
||||||
Given an array of integers nums sorted in non-decreasing order,
|
Given an array of integers nums sorted in non-decreasing order,
|
||||||
find the starting and ending position of a given target value.
|
find the starting and ending position of a given target value.
|
||||||
|
|
||||||
If target is not found in the array, return [-1, -1].
|
If target is not found in the array, return [-1, -1].
|
||||||
|
|
||||||
Leetcode ref:
|
Leetcode ref:
|
||||||
https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/
|
https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
|
||||||
|
def search_range(nums: list[int], target: int) -> list[int]:
|
||||||
def searchRange(nums: list[int], target: int) -> list[int]:
|
|
||||||
"""
|
"""
|
||||||
>>> searchRange([5,7,7,8,8,10],8)
|
>>> searchRange([5,7,7,8,8,10],8)
|
||||||
[3, 4]
|
[3, 4]
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
"""
|
"""
|
||||||
Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.
|
Given an integer n, return all the numbers in the range [1, n]
|
||||||
|
sorted in lexicographical order.
|
||||||
|
|
||||||
You must write an algorithm that runs in O(n) time and uses O(1) extra space.
|
You must write an algorithm that runs in O(n) time and uses O(1) extra space.
|
||||||
|
|
||||||
Leetcode reference: https://leetcode.com/problems/lexicographical-numbers/
|
Leetcode reference: https://leetcode.com/problems/lexicographical-numbers/
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
def lexicalOrder(n: int) -> list[int]:
|
def lexical_order(n: int) -> list[int]:
|
||||||
"""
|
"""
|
||||||
>>> lexicalOrder(13)
|
>>> lexicalOrder(13)
|
||||||
[1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9]
|
[1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||||
|
Loading…
Reference in New Issue
Block a user