This file contains hidden or 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
| # Course Schedule | |
| class Solution: | |
| #Finding cycle exits in a directed graph | |
| def canFinish(self, numCourses, prerequisites): | |
| graph = [[] for _ in range(numCourses)] | |
| visit = [0 for _ in range(numCourses)] | |
| for x, y in prerequisites: | |
| graph[x].append(y) | |
| def dfs(i): |
This file contains hidden or 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
| #142 Linked List Cycle II | |
| class Solution(object): | |
| def detectCycle(self, head): | |
| """ | |
| :type head: ListNode | |
| :rtype: ListNode | |
| """ | |
| if not head: | |
| return None | |
| slow = fast = head |
This file contains hidden or 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
| #Min stack | |
| class MinStack: | |
| def __init__(self): | |
| """ | |
| initialize your data structure here. | |
| """ | |
| self.stack = [] | |
| def push(self, x): |
This file contains hidden or 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
| #Same Tree | |
| class Solution: | |
| def isSameTree(self, p, q): | |
| """ | |
| :type p: TreeNode | |
| :type q: TreeNode | |
| :rtype: bool | |
| """ | |
| result = self.isSame(p,q) | |
| return result |
This file contains hidden or 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
| class Solution: | |
| def searchMatrix(self, matrix, target): | |
| """ | |
| :type matrix: List[List[int]] | |
| :type target: int | |
| :rtype: bool | |
| """ | |
| if not matrix or not matrix[0]: | |
| return False | |
| row,col = len(matrix),len(matrix[0]) |
This file contains hidden or 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
| class Solution: | |
| def compareVersion(self, version1, version2): | |
| """ | |
| :type version1: str | |
| :type version2: str | |
| :rtype: int | |
| """ | |
| version1 = version1.split(".") | |
| version2 = version2.split(".") | |
| longer_length = max(len(version1),len(version2)) |
This file contains hidden or 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
| import math | |
| class Solution: | |
| def search(self,nums,target): | |
| low = 0 | |
| high = len(nums) - 1 | |
| while low <=high: | |
| mid = math.floor((low+high)/2) | |
| if target == nums[mid]: | |
| return mid | |
This file contains hidden or 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
| Result: 1 | |
| Items { | |
| TemplateId: "BADGE_BATTLE_ATTACK_WON" | |
| Badge { | |
| BadgeType: BADGE_BATTLE_ATTACK_WON | |
| BadgeRanks: 4 | |
| Targets: "\nd\350\007" | |
| } | |
| } | |
| Items { |