Skip to content

PR-3 - HF Attempt #1066

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions Python/combinationSum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution(object):
def combinationSum(self, candidates, target):
ret = []
self.dfs(candidates, target, [], ret)
return ret

def dfs(self, nums, target, path, ret):
if target < 0:
return
if target == 0:
ret.append(path)
return
for i in range(len(nums)):
self.dfs(nums[i:], target-nums[i], path+[nums[i]], ret)
10 changes: 10 additions & 0 deletions Python/recentCOunter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class RecentCounter:

def __init__(self):
self.p = collections.deque()

def ping(self, t):
self.p.append(t)
while self.p[0] < t - 3000:
self.p.popleft()
return len(self.p)
43 changes: 43 additions & 0 deletions Python/rotateList.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Solution(object):
def rotateRight(self, head, k):
"""
:type head: ListNode
:type k: int
:rtype: ListNode
"""
if not head:
return None

if head.next == None:
return head

pointer = head
length = 1

while pointer.next:
pointer = pointer.next
length += 1

rotateTimes = k%length

if k == 0 or rotateTimes == 0:
return head

fastPointer = head
slowPointer = head

for a in range (rotateTimes):
fastPointer = fastPointer.next


while fastPointer.next:
slowPointer = slowPointer.next
fastPointer = fastPointer.next

temp = slowPointer.next

slowPointer.next = None
fastPointer.next = head
head = temp

return head