Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/medium/pow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@

class Solution:
def myPow(self, x, n):
if n < 0:
return self.myPow(1.0 / x, -n)
else:
if n == 0:
return 1
if n % 3 == 0:
third = self.myPow(x, n / 3)
return third * third * third
elif n % 3 == 1:
third = self.myPow(x, (n - 1) / 3)
return x * third * third * third
else:
third = self.myPow(x, (n - 2) / 3)
return x * x * third * third * third

def myPow_back(self, x, n):
if n > 0:
if n == 1:
return x
Expand All @@ -22,10 +38,9 @@ def myPow(self, x, n):
return float(1 / x)
else:
return 1 / (x * (1 / self.myPow(x, n + 1)))
pow(2,3)


if __name__ == "__main__":
ss = Solution()
print(ss.myPow(1.001, 998))
print(ss.myPow(2, -2))
print("hello imp")
20 changes: 20 additions & 0 deletions src/medium/restore_ip_addresses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
@author: loopgan
@contact: [email protected]
@time: 18-8-28 下午11:51
"""


class Solution:
def restoreIpAddresses(self, s):
pass


if __name__ == "__main__":
s = "25525511135"
ss = Solution()
print(ss.restoreIpAddresses(s))
print("Hello imp")