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
| tlst = [('a1','b1','q1','p1'), | |
| ('a2','b2','q2','p2'), | |
| ('a3','b3','q3','p3')] | |
| names = 'area brand question price'.split() | |
| lst = [{name:value for name, value in zip(names, t)} for t in tlst] | |
| print(lst) |
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 findRadius(self, houses, heaters): | |
| """ | |
| :type houses: List[int] | |
| :type heaters: List[int] | |
| :rtype: int | |
| """ | |
| ans = 0 | |
| heaters.sort() | |
| for house in houses: |
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 countAndSay(self, n): | |
| """ | |
| :type n: int | |
| :rtype: str | |
| """ | |
| s = '1' | |
| for i in range(1, n): | |
| s = self.cal(s) | |
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 maxDistToClosest(self, seats): | |
| """ | |
| :type seats: List[int] | |
| :rtype: int | |
| """ | |
| hasSeats = [] | |
| len_seats = len(seats) | |
| count = 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 licenseKeyFormatting(self, S, K): | |
| """ | |
| :type S: str | |
| :type K: int | |
| :rtype: str | |
| """ | |
| S =''.join(S.split('-')) | |
| S = str.upper(S) | |
| temp = '' |
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 dominantIndex(self, nums): | |
| """ | |
| :type nums: List[int] | |
| :rtype: int | |
| """ | |
| maxn = max(nums) | |
| for num in nums: | |
| if num != maxn and 2 * num > maxn: | |
| return -1 |
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 longestWord(self, words): | |
| """ | |
| :type words: List[str] | |
| :rtype: str | |
| """ | |
| wSet =set(['']) | |
| ans = '' | |
| for word in sorted(words): |
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 findLengthOfLCIS(self, nums): | |
| """ | |
| :type nums: List[int] | |
| :rtype: int | |
| """ | |
| nums_length = len(nums) | |
| if nums_length <=1: | |
| return nums_length | |
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 nextGreatestLetter(self, letters, target): | |
| """ | |
| :type letters: List[str] | |
| :type target: str | |
| :rtype: str | |
| """ | |
| letters = set(map(ord, letters)) | |
| for x in range(1, 27): | |
| candidate = ord(target) + 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
| class Solution: | |
| def minCostClimbingStairs(self, cost): | |
| """ | |
| :type cost: List[int] | |
| :rtype: int | |
| """ | |
| size = len(cost) | |
| dp = [cost[0], cost[1]] | |
| for x in range(2, size): | |
| dp.append(min(dp[x -1], dp[x-2]) + cost[x]) |