当前位置:网站首页>Leetcode must review six lintcode (28348455116385)
Leetcode must review six lintcode (28348455116385)
2022-06-23 21:44:00 【Learning uncle】
List of articles
283 · The maximum of the three numbers
Give three integers , Find the maximum of them .
def maxOfThreeNumbers(self, num1, num2, num3):
# write your code here
max_val = float('-inf')
if num1 > num2:
max_val = num1
else:
max_val = num2
return max_val if max_val > num3 else num3

484 · Swap two elements of an array
I'll give you an array and two indexes , Exchange the numbers subscript to the two indexes

def swapIntegers(self, A, index1, index2):
# write your code here
A[index1], A[index2] = A[index2], A[index1]

455 · Student number
Implement a program called Class Class , Contains the following properties and methods :
One public Of students attribute , It's a Student Class array .
A constructor , Take a parameter n, There are... In the class n A student . Constructor needs to create n Instance objects of students and put them in students In this member , Each student is created in the order , Student numbers need to be marked as 0, 1, 2 … n-1.

I didn't understand the question at first , Looking back at what I wrote before .
def __init__(self, n):
self.students = []
for i in range(n):
self.students.append(Student(i))
116 · Jumping game
Give an array of nonnegative integers , You are initially positioned in the first position of the array .
Each element in the array represents the maximum length that you can jump at that location .
Determine if you can reach the last position of the array .

I should be greedy , It is uncertain whether it is greed or dynamic planning
def canJump(self, A):
# write your code here
for i in range(len(A) - 1, 0, -1):
for j in range(i - 1, -1, -1):
if j + A[j] >= i:
break
else:
return False
return True
The following is the teacher's solution in class , I don't remember at all .
Dynamic programming 1

Dynamic programming 2


The law of greed 

385 · The dynamic array

class ArrayListManager:
''' * @param n: You should generate an array list of n elements. * @return: The array list your just created. '''
def create(self, n):
# Write your code here
if n >= 0:
self.arr = list(range(n))
return self.arr
''' * @param list: The list you need to clone * @return: A deep copyed array list from the given list '''
def clone(self, list):
# Write your code here
return list[:]
''' * @param list: The array list to find the kth element * @param k: Find the kth element * @return: The kth element '''
def get(self, list, k):
# Write your code here
return list[k]
''' * @param list: The array list * @param k: Find the kth element, set it to val * @param val: Find the kth element, set it to val '''
def set(self, list, k, val):
# write your code here
list[k] = val
''' * @param list: The array list to remove the kth element * @param k: Remove the kth element '''
def remove(self, list, k):
# write tour code here
list.remove(k)
''' * @param list: The array list. * @param val: Get the index of the first element that equals to val * @return: Return the index of that element '''
def indexOf(self, list, val):
# Write your code here
for i in range(len(list)):
if list[i] == val:
return i
else:
return -1
边栏推荐
- The new track of flagship chip is finally clear
- Common commands for cleaning up kubernetes cluster resources
- Raid card with hardware knowledge (5)
- DM sub database and sub table DDL "optimistic coordination" mode introduction - tidb tool sharing
- Analysis of a series a e-commerce app docommandnative
- Connect edgex gateway to thingsboard IOT platform
- Smart cockpit SOC competition upgraded, and domestic 7Nm chips ushered in an important breakthrough
- It's very interesting. Make an app to decorate the Christmas hat on Christmas!
- Is it safe to open an account for flush stock?
- Cloud database smooth disassembly scheme
猜你喜欢

蓝牙芯片|瑞萨和TI推出新蓝牙芯片,试试伦茨科技ST17H65蓝牙BLE5.2芯片

Outlook開機自啟+關閉時最小化

New SQL syntax quick manual!

How to view the role of PMO in agile organizations?

Find my information | Apple may launch the second generation airtag. Try the Lenz technology find my solution

Embedded development: embedded foundation -- the difference between restart and reset

大一女生废话编程爆火!懂不懂编程的看完都拴Q了

Minimisé lorsque Outlook est allumé + éteint

How to calculate individual income tax? You know what?

Selenium批量查询运动员技术等级
随机推荐
Facing the problem of lock waiting, how to realize the second level positioning and analysis of data warehouse
Cool 3D sphere text cloud effect!
How to correctly divide data into databases and tables
Improve efficiency, take you to batch generate 100 ID photos with QR code
How does the video platform deployment give corresponding user permissions to the software package files?
Selenium批量查询运动员技术等级
What is the use of PMP certification?
ZABBIX custom monitoring item (server monitoring)
How many of the five app automated test AIDS have you used?
Analysis of Alibaba cloud Tianchi competition -- prediction of o2o coupon
Is PMP necessary?
实验五 模块、包和库
Raid card with hardware knowledge (5)
HDLBits->Circuits->Arithmetic Circuitd->3-bit binary adder
Supplementary usage of upload component in fusiondesign 1
TDD development mode recommendation process
Start optimization - directed acyclic graph
How to view the hard disk of ECS? How about the speed and stability of the server
Polling and connection
Prometheus primary body test