jack-lee-hiter / algorithmsbypython Goto Github PK
View Code? Open in Web Editor NEW算法/数据结构/Python/剑指offer/机器学习/leetcode
算法/数据结构/Python/剑指offer/机器学习/leetcode
二维数组查找的类型判断这部分代码想请教一下,没看懂
if type(target) == float and type(array[0][0]) == int:
if int(target) == target:
return False
target = int(target)
elif type(target) == int and type(array[0][0]) == float:
target = float(int)
elif type(target) != type(array[0][0]): # 浮点数的相等判断问题需要特别注意, 一般都是判断两个数的差值是否小于一个特别小的数。这里不展开分析。
return False
哦哦,应该是你的方法2了
# 删除堆顶元素后, 交换堆尾和空堆顶的位置并实现元素的下沉
def percDown(self, i):
while (i*2) <= self.currentSize:
mc = self.minChild(i)
if self.heapList[i] > self.heapList[mc]:
temp = self.heapList[i]
self.heapList[i] = self.heapList[mc]
self.heapList[mc] = temp
else:
break
if type(target) == float and type(array[0][0]) == int:
if int(target) == target: #这里的==应该是!=吧 第三个测试例子也因为这个==,
#导致13.0输出为False,但是明明array里有13
return False
1.更高效的表达大数
2.实现任意两个整数的加法
应该是self.data = newdata。而不是self.next = newdata。
elif rotateArray[mid] == rotateArray[front] and rotateArray[front] == rotateArray[rear]:
for i in range(1, len(rotateArray)):
if rotateArray[i] < minVal:
minVal = rotateArray[i]
rear = i
这一段代码,mid,front,rear的值都一样之后,遍历整个数组找出最小值了,应该就直接return吧,怎么又进循环了。这里又多循环几次,切到只剩两个数了才出循环,不是做白工了吗。第一次就已经在整个list里遍历了一遍,找出最小值了,再循环没意义啊。
剑指里面试题6:从尾到头打印链表,复制到牛客的编辑器里,一直报这个错 'NoneType' object has no attribute 'val'。不知道为什么。看不出来原因。
说实话我没看明白lz写的,但是测试了下我的,居然一样
class Solution:
def minNumberInRotateArray(self, rotateArray):
if len(rotateArray)==0:
return 0
head =0
rear = len(rotateArray)-1
while rotateArray[head]<=rotateArray[head+1]:
head+=1
return rotateArray[head+1]
def transTriple(triple):
m, n = shape(triple)
transMatrix = []
# sortedIndex = array([m[1] for m in triple]).argsort()
for i in range(m):
# tempArray = triple[sortedIndex[i]]
tempArray = triple[i]
transMatrix.append([tempArray[1], tempArray[0], tempArray[2]])
return transMatrix
#num1, num2 = 0
应为
num1, num2 = 0 ,0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.