摘要: 63. 不同路径 II class Solution: def uniquePathsWithObstacles1(self, obstacleGrid: List[List[int]]) -> int: m, n = len(obstacleGrid), len(obstacleGrid[0]) 阅读全文
posted @ 2020-03-19 11:59 7aughing 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 1. numbers of islands 1 class Solution(object): 2 def dfs(self,grid,i,j): 3 m,n=len(grid),len(grid[0]) 4 5 for k in range(4): 6 nx,ny=i+self.dirs[k],j 阅读全文
posted @ 2020-03-16 19:31 7aughing 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 1.hashtable 1 class Node: 2 def __init__(self,key,val): 3 self.pair=(key,val) 4 self.next=None # next仍指向一个Node 5 6 class MyHashMap(object): 7 8 def __ 阅读全文
posted @ 2020-03-16 18:13 7aughing 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 1.search range 1 class Solution(object): 2 def searchRange(self, nums, target): 3 res=[-1,-1] 4 if(len(nums)==0): 5 return res 6 7 left,right=0,len(nu 阅读全文
posted @ 2020-03-16 12:37 7aughing 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 1. rand7生成rand10 1 # The rand7() API is already defined for you. 2 # def rand7(): 3 # @return a random integer in the range 1 to 7 4 5 class Solution( 阅读全文
posted @ 2020-03-16 09:01 7aughing 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 1. reverse LinkedList 1 class ListNode: 2 def __init__(self,x): 3 self.val=x 4 self.next=None 5 6 class Solution: 7 def reverse(self,head): 8 if(head= 阅读全文
posted @ 2020-03-15 11:22 7aughing 阅读(126) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int longestValidParentheses(string s) { if(s.size()<2) return 0; int n=s.size(); int res=0; vector<int> dp(n,0); //dp[i]表示以nu 阅读全文
posted @ 2020-03-07 18:22 7aughing 阅读(132) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int search(vector<int>& nums, int target) { if(nums.size()==0) return -1; int left=0,right=nums.size()-1; while(left+1<right) 阅读全文
posted @ 2020-03-07 18:04 7aughing 阅读(129) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: void nextPermutation(vector<int>& nums) { if(nums.size()<=1) return; int i=nums.size()-2; while(i>=0 && nums[i]>=nums[i+1]){ 阅读全文
posted @ 2020-03-07 17:44 7aughing 阅读(108) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: void dfs(int n, int left, int right, string path, vector<string>& res){ if(right==n){ res.push_back(path); return; } if(left< 阅读全文
posted @ 2020-03-07 17:24 7aughing 阅读(160) 评论(0) 推荐(0) 编辑