forked from taizilongxu/Leetcode-Py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request SocialfiPanda#7 from resorcap/master
Create Excel Sheet Column Number.py
- Loading branch information
Showing
4 changed files
with
23 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Solution: | ||
def titleToNumber(self, s): | ||
num = 0 | ||
for i in s: | ||
num *= 26 | ||
num += ord(i) - 64 | ||
return num |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Solution: | ||
def largestNumber(self, num): | ||
num = [str(x) for x in num] | ||
num.sort(cmp = lambda x, y: cmp(y+x, x+y)) | ||
return ''.join(num).lstrip('0') or '0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
class Solution: | ||
def removeNthFromEnd(self, head, n): | ||
fast, slow, prev = head, head, None | ||
while n > 0: | ||
fast, n = fast.next, n - 1 | ||
while fast != None: | ||
fast, slow, prev = fast.next, slow.next, slow | ||
if prev == None: | ||
return head.next | ||
prev.next = prev.next.next | ||
return head | ||
dummy = ListNode(-1) | ||
dummy.next = head | ||
left, right = dummy, dummy | ||
while n: | ||
right, n = right.next, n-1 | ||
while right.next: | ||
right = right.next | ||
left = left.next | ||
left.next = left.next.next | ||
return dummy.next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
class Solution: | ||
def reverseWords(self, s): | ||
return " ".join(filter(lambda x: x, reversed(s.split(" ")))) | ||
return " ".join(filter(None, reversed(s.split(" ")))) |