摘要: 给你无向 连通 图中一个节点的引用,请你返回该图的 深拷贝(克隆)。 图中的每个节点都包含它的值 val(int) 和其邻居的列表(list[Node])。 class Node { public int val; public List<Node> neighbors; } 测试用例格式: 简单起 阅读全文
posted @ 2020-03-22 09:37 7aughing 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 1312. Minimum Insertion Steps to Make a String Palindrome # 双指针,一头一尾。如果left和right所指字符相同,那么left+1,right-1 # 如果不同,则表示需要插入字符了。有两种可能的插入方法: # 在left-1处插入rig 阅读全文
posted @ 2020-03-21 10:37 7aughing 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 746. Min Cost Climbing Stairs 数组的每个索引做为一个阶梯,第 i个阶梯对应着一个非负数的体力花费值 cost[i](索引从0开始)。 每当你爬上一个阶梯你都要花费对应的体力花费值,然后你可以选择继续爬一个阶梯或者爬两个阶梯。 您需要找到达到楼层顶部的最低花费。在开始时, 阅读全文
posted @ 2020-03-21 08:59 7aughing 阅读(179) 评论(0) 推荐(0) 编辑
摘要: lc10, *可以匹配0个或者多个前一个字符 1 class Solution(object): 2 def isMatch(self, s, p): 3 """ 4 :type s: str 5 :type p: str 6 :rtype: bool 7 """ 8 m=len(s)+1 9 n= 阅读全文
posted @ 2020-03-21 00:27 7aughing 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 给定一个由 '(' 和 ')' 括号组成的字符串 S,我们需要添加最少的括号( '(' 或是 ')',可以在任何位置),以使得到的括号字符串有效。 从形式上讲,只有满足下面几点之一,括号字符串才是有效的: 它是一个空字符串,或者 它可以被写成 AB (A 与 B 连接), 其中 A 和 B 都是有效 阅读全文
posted @ 2020-03-20 23:29 7aughing 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution(object): 2 def isValid(self, s): 3 """ 4 :type s: str 5 :rtype: bool 6 """ 7 dic={')':'(',']':'[','}':'{'} 8 stack=[] 9 for i in rang 阅读全文
posted @ 2020-03-20 22:39 7aughing 阅读(102) 评论(0) 推荐(0) 编辑
摘要: 1 # Definition for singly-linked list. 2 # class ListNode(object): 3 # def __init__(self, x): 4 # self.val = x 5 # self.next = None 6 7 class Solution 阅读全文
posted @ 2020-03-20 22:34 7aughing 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution(object): 2 def longestPalindrome(self, s): 3 """ 4 :type s: str 5 :rtype: str 6 """ 7 if(len(s)<2): 8 return s 9 10 left,right=0,0 11 阅读全文
posted @ 2020-03-20 22:20 7aughing 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 1 from collections import defaultdict 2 class Solution(object): 3 def lengthOfLongestSubstring(self, s): 4 """ 5 :type s: str 6 :rtype: int 7 """ 8 9 阅读全文
posted @ 2020-03-20 22:06 7aughing 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 对二叉树进行dfs 1 # Definition for a binary tree node. 2 # class TreeNode(object): 3 # def __init__(self, x): 4 # self.val = x 5 # self.left = None 6 # self 阅读全文
posted @ 2020-03-20 21:48 7aughing 阅读(116) 评论(0) 推荐(0) 编辑