algorhythms / leetcode Goto Github PK
View Code? Open in Web Editor NEWLeetCode In Action - Python (705+)
License: MIT License
LeetCode In Action - Python (705+)
License: MIT License
Input: "aaaaaaaa", ["aa","aa","aa"]
Output: [0,2]
Expected: [0,1,2]
I tried doing self.stack.append(x) and self.stack = [x]+self.stack, but I get the error in both cases.
The code in '106 Construct Binary Tree from Preorder and Inorder Traversal.py' causes a MLE error now. It may be better to use integer than list in recursion.
my code is as below:
n = 0
while self.head:
if random.randint(0,n)==0:
res = self.head.val
n += 1
self.head = self.head.next
return res
yes,for test ["Solution","getRandom","getRandom","getRandom"]
[[[3]],[],[],[]]
it raised UnboundLocalError: local variable 'res' referenced before assignment
but, if I name new var to make it equal to self.head: ss = self.head , AC!!!!!
n = 0
ss = self.head
while ss:
if random.randint(0,n)==0:
res = ss.val
n += 1
ss.head = ss.next
return res
I am so confused!
Hi,
I appreciate your concise and readable code. However, I think you ignored the integer overflow situation in your solution for question 029-Divide-Two-Integers :-)
https://github.com/algorhythms/LeetCode/blob/master/027%20Divide%20Two%20Integers.py
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.