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
| from collections import defaultdict | |
| class Solution: | |
| def threeSum(self, nums: List[int]) -> List[List[int]]: | |
| nums_count_map = defaultdict(int) | |
| result_set = set() | |
| for n in nums: | |
| nums_count_map[n] += 1 | |
| for n in nums_count_map: | |
| for m in nums_count_map: |
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
| from scipy.io import loadmat | |
| import numpy as np | |
| import scipy.optimize as opt | |
| import matplotlib.pyplot as plt | |
| def sigmoid(z): | |
| return 1/(1+np.exp(-z)) | |
| def costFunctionReg(theta, X, y, lmbda): | |
| m = len(y) |
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
| # Copyright (c) 2018 Ultimaker B.V. | |
| # Cura is released under the terms of the LGPLv3 or higher. | |
| from ..Script import Script | |
| from UM.Application import Application #To get the current printer's settings. | |
| from UM.Logger import Logger | |
| class PauseAtTopAndBottom(Script): | |
| def __init__(self): |
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(object): | |
| def findLadders(self, beginWord, endWord, wordList): | |
| """ | |
| :type beginWord: str | |
| :type endWord: str | |
| :type wordList: List[str] | |
| :rtype: List[List[str]] | |
| """ | |
| connection = {w: set() for w in wordList} | |
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(object): | |
| def numDistinctIslands(self, grid): | |
| """ | |
| :type grid: List[List[int]] | |
| :rtype: int | |
| """ | |
| def get_island(oi, oj, grid): | |
| lands = [] | |
| def dfs(i, j, grid): | |
| if i < 0 or j < 0: return |
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
| # Definition for a binary tree node. | |
| # class TreeNode(object): | |
| # def __init__(self, x): | |
| # self.val = x | |
| # self.left = None | |
| # self.right = None | |
| class Solution(object): | |
| def constructMaximumBinaryTree(self, nums): | |
| """ |
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(object): | |
| def searchMatrix(self, matrix, target): | |
| """ | |
| :type matrix: List[List[int]] | |
| :type target: int | |
| :rtype: bool | |
| """ | |
| def search( tl, br ): | |
| print 'Searching...' |
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(object): | |
| def shortestPalindrome(self, s): | |
| """ | |
| :type s: str | |
| :rtype: str | |
| """ | |
| def non_palindrome_index(s): | |
| i = 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(object): | |
| def largestDivisibleSubset(self, nums): | |
| """ | |
| :type nums: List[int] | |
| :rtype: List[int] | |
| """ | |
| if not nums: return [] | |
| from_big_nums = sorted(nums) | |
| dp = [] | |
| for i,n in enumerate(from_big_nums): |
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(object): | |
| def findContestMatch(self, n): | |
| """ | |
| :type n: int | |
| :rtype: str | |
| """ | |
| def wrap_thing(a, b): | |
| return '({},{})'.format(a,b) | |
| to_wrap = [i for i in range(1,n+1)] | |
| while len(to_wrap) > 1: |