mirror of
https://github.com/SunnyQjm/algorithm-review.git
synced 2026-06-09 09:29:27 +08:00
update
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
# -10^4 <= target <= 10^4
|
||||
##############################################################################
|
||||
|
||||
|
||||
class Solution:
|
||||
def threeSumClosest(self, nums, target):
|
||||
"""
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
# 尽管上面的答案是按字典序排列的,但是你可以任意选择答案输出的顺序。
|
||||
########################################################################################################
|
||||
|
||||
|
||||
class Solution:
|
||||
numMap = {'2': "abc", '3': "def", '4': "ghi", '5': "jkl", '6': "mno", '7': "pqrs", '8': "tuv", '9': "wxyz"}
|
||||
|
||||
def letterCombinations(self, digits):
|
||||
"""
|
||||
:type digits: str
|
||||
@@ -29,6 +31,7 @@ class Solution:
|
||||
1. 这是一个回溯问题,且没有最优子结构,不能用动态规划,所以可以使用回溯框架用递归方式解决;
|
||||
回溯框架套路看这里 => https://labuladong.gitbook.io/algo/di-ling-zhang-bi-du-xi-lie/hui-su-suan-fa-xiang-jie-xiu-ding-ban
|
||||
"""
|
||||
|
||||
def _letterCombinations(path, digits, index, result):
|
||||
"""
|
||||
:type path: str => 当前路径
|
||||
|
||||
@@ -17,15 +17,17 @@
|
||||
# 你能尝试使用一趟扫描实现吗?
|
||||
###################################################################################
|
||||
|
||||
|
||||
class ListNode:
|
||||
def __init__(self, x):
|
||||
self.val = x
|
||||
self.next = None
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
if self:
|
||||
return "{}->{}".format(self.val, repr(self.next))
|
||||
|
||||
|
||||
class Solution:
|
||||
def removeNthFromEnd(self, head, n):
|
||||
"""
|
||||
@@ -51,7 +53,7 @@ class Solution:
|
||||
while right:
|
||||
pre, left, right = left, left.next, right.next
|
||||
|
||||
if not pre: # 处理要删除的节点是头节点的情况
|
||||
if not pre: # 处理要删除的节点是头节点的情况
|
||||
return head.next
|
||||
else:
|
||||
pre.next = left.next
|
||||
|
||||
Reference in New Issue
Block a user