当前位置:网站首页>AttributeError: ‘NoneType‘ object has no attribute ‘sort‘
AttributeError: ‘NoneType‘ object has no attribute ‘sort‘
2022-07-19 04:17:00 【Just change your name】
reason
It may be when returning a function , This function returns nothing
For example, one is returned here dfs function , This function itself does not return anything , So wrong reporting
from typing import (
List,
)
import math
class Solution:
"""
@param n: An integer
@return: a list of combination
we will sort your return value in output
"""
def dfs(self, n, start, sub_ans, ans):
if start <= 1:
if len(sub_ans) > 1:
ans.append(sub_ans[:])
return
for i in range(start, int(math.sqrt(n))+1):
if n%i == 0:
sub_ans.append(i)
self.dfs(n//i, i, sub_ans, ans)
sub_ans.pop()
if start <= n:
sub_ans.append(n)
self.dfs(1, 1, sub_ans, ans)
sub_ans.pop()
def get_factors(self, n: int) -> List[List[int]]:
# write your code here
ans = []
return self.dfs(n, 2, [], ans) # There is a mistake here
solve
Call this function directly , Return the previously defined reference passing variables that participate in the function as parameters .
For example, call directly here dfs, return ans.
from typing import (
List,
)
import math
class Solution:
"""
@param n: An integer
@return: a list of combination
we will sort your return value in output
"""
def dfs(self, n, start, sub_ans, ans):
if start <= 1:
if len(sub_ans) > 1:
ans.append(sub_ans[:])
return
for i in range(start, int(math.sqrt(n))+1):
if n%i == 0:
sub_ans.append(i)
self.dfs(n//i, i, sub_ans, ans)
sub_ans.pop()
if start <= n:
sub_ans.append(n)
self.dfs(1, 1, sub_ans, ans)
sub_ans.pop()
def get_factors(self, n: int) -> List[List[int]]:
# write your code here
ans = []
self.dfs(n, 2, [], ans) # Call directly
return ans # Return reference transfer variable
边栏推荐
- Niuke 2021 training League warm-up training match interstellar love (and search Collection)
- 小程序毕设作品之微信电子书阅读小程序毕业设计(5)任务书
- EAS(能量感知调度)绿色节能调度器
- [super cloud terminal to create a leading opportunity] local computing cloud management, Intel helps digitalize Education
- 【数据库】期末必知必会-----第九章 数据库设计
- 【数据库】期末必知必会-----第七章 数据库完整性
- [database] must know at the end of the term ----- Chapter 2 relational data model
- 机器学习11:代价敏感学习
- [database] must know at the end of the term ----- Chapter 6 experiment
- 巧用企业网盘收取报告或总结
猜你喜欢

C# 字符串(string)常用方法

Skillfully use enterprise network disk to collect reports or summaries

Nearly 90% of servers can be saved, but the anti fraud efficiency has increased significantly. Why is PayPal's plan to break the "Ai memory wall" so cost-effective?

ASP.NET1==visual studio创建asp.net demo

小程序毕设作品之微信在线教育视频点播学习小程序毕业设计(3)后台功能

高性能与经济性兼备:傲腾 持久内存助力移动云应对严苛内存挑战

Leetcode7 DFS + dynamic programming + double pointer

Matlab drawing activation function sigmoid, relu

Unity - 如何修改一个 Package 或是如何将 Package Local化

英特尔助力开立医疗推动超声产检智能化
随机推荐
Find the central subscript of the array
Wechat e-book reading applet graduation project (6) opening defense ppt
How does the enterprise post office set up SPF records?
Intel experts share: how to program efficiently on XPU architecture? Zhiqiang Research Institute
C# 字符串(string)常用方法
Data interaction between avframe\avpacket and itself in ffmpeg
Niuke 2021 training League warm-up training match interstellar love (and search Collection)
若依框架包名修改器
Nearly 90% of servers can be saved, but the anti fraud efficiency has increased significantly. Why is PayPal's plan to break the "Ai memory wall" so cost-effective?
寻找数组的中心下标
Chapter 6 performance platform godeye source code analysis - Custom expansion module
【数据库】期末必知必会-----第七章 数据库完整性
机器学习09:无监督学习
Chapter 4 performance platform godeye source code analysis - monitoring module
关于数据库的问题,唯一和非重复的概念
Vs Code common shortcut keys
Wechat online education video on demand learning applet graduation design (3) background function
How to filter viruses / spam more effectively!
高性能与经济性兼备:傲腾 持久内存助力移动云应对严苛内存挑战
Wechat Online Education video on Demand Learning of applet Graduation Design (3) Background Function