leetcode problem

This commit is contained in:
jeevaramanthan.m 2023-10-09 09:55:05 +05:30
parent 6977cdaf29
commit a854521dcb
2 changed files with 8 additions and 9 deletions

View File

@ -2,17 +2,16 @@
Problem: Find First and Last Position of Element in Sorted Array
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.
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/
"""
from __future__ import annotations
def searchRange(nums: list[int], target: int) -> list[int]:
def search_range(nums: list[int], target: int) -> list[int]:
"""
>>> searchRange([5,7,7,8,8,10],8)
[3, 4]

View File

@ -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/
"""
from __future__ import annotations
def lexicalOrder(n: int) -> list[int]:
def lexical_order(n: int) -> list[int]:
"""
>>> lexicalOrder(13)
[1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9]