
leetcode
MVincent
这个作者很懒,什么都没留下…
展开
-
leetcode 9 Palindrome Number
c++:class Solution {public: bool isPalindrome(int x) { if(x<0) return false; std::string str = std::to_string(x); for(std::string::iterator i = str.begin(), j = str.end...原创 2018-06-03 14:51:05 · 167 阅读 · 0 评论 -
leetcode 387 First Unique Character in a String
python:class Solution: def firstUniqChar(self, s): """ :type s: str :rtype: int """ l = dict() for i in list(s): if i in l: ...原创 2018-07-13 14:49:17 · 199 阅读 · 0 评论 -
leetcode 88 Merge Sorted Array
python:class Solution(object): def merge(self, nums1, m, nums2, n): """ :type nums1: List[int] :type m: int :type nums2: List[int] :type n: int :...原创 2018-09-07 19:02:18 · 171 阅读 · 0 评论 -
leetcode 804 Unique Morse Code Words
python:class Solution: def uniqueMorseRepresentations(self, words): """ :type words: List[str] :rtype: int """ m = [".-","-...","-.-.","-.."原创 2018-09-11 16:41:09 · 230 阅读 · 0 评论 -
leetcode 69 Sqrt(x)
python:class Solution: def mySqrt(self, x): """ :type x: int :rtype: int """ left = 0 right = x while (left <= right): mid...原创 2018-09-03 14:52:14 · 204 阅读 · 0 评论 -
leetcode 859 Buddy Strings
python:class Solution: def buddyStrings(self, A, B): """ :type A: str :type B: str :rtype: bool """ if A == B: return len(set(A)) !=...原创 2018-09-12 15:41:16 · 218 阅读 · 0 评论 -
leetcode 118 Pascal's Triangle
python:class Solution: def generate(self, numRows): """ :type numRows: int :rtype: List[List[int]] """ res = [] arr = [1]*numRows ...原创 2018-09-10 16:52:25 · 183 阅读 · 0 评论 -
leetcode 645 Set Mismatch
python:class Solution: def findErrorNums(self, nums): """ :type nums: List[int] :rtype: List[int] """ l = len(nums) res = [] res.append(s...原创 2018-09-13 15:09:11 · 337 阅读 · 0 评论 -
leetcode 202 Happy Number
python:class Solution: def isHappy(self, n): """ :type n: int :rtype: bool """ check = [n] while (n != 1): t = 0 for j in...原创 2018-09-27 10:47:36 · 156 阅读 · 0 评论 -
leetcode 872 Leaf-Similar Trees
python:class Solution: def leafSimilar(self, root1, root2): """ :type root1: TreeNode :type root2: TreeNode :rtype: bool """ def leaf(root): ...原创 2018-09-28 09:52:59 · 186 阅读 · 0 评论 -
leetcode 739 Daily Temperatures
python:class Solution: def dailyTemperatures(self, temperatures): """ :type temperatures: List[int] :rtype: List[int] """ stack = [[temperatures[0], 0]]...原创 2018-10-07 21:37:00 · 225 阅读 · 0 评论 -
leetcode 257 Binary Tree Paths
python:class Solution(object): def binaryTreePaths(self, root): """ :type root: TreeNode :rtype: List[str] """ path = '' res = [] self.Tr...原创 2018-10-08 10:08:15 · 208 阅读 · 0 评论 -
733 Flood Fill
python:class Solution: def floodFill(self, image, sr, sc, newColor): """ :type image: List[List[int]] :type sr: int :type sc: int :type newColor: int ...原创 2018-10-17 16:52:43 · 291 阅读 · 0 评论 -
leetcode 155 Min Stack
python:class MinStack: def __init__(self): """ initialize your data structure here. """ self.stack = [] def push(self, x): """ :ty...原创 2018-10-25 09:39:17 · 232 阅读 · 0 评论 -
819 Most Common Word
python;class Solution: def mostCommonWord(self, paragraph, banned): """ :type paragraph: str :type banned: List[str] :rtype: str """ res = ('', -...原创 2018-10-23 16:49:32 · 298 阅读 · 0 评论 -
leetcode 141 Linked List Cycle
python:class Solution(object): def hasCycle(self, head): """ :type head: ListNode :rtype: bool """ if not head: return False ...原创 2018-10-29 11:05:28 · 194 阅读 · 0 评论 -
leetcode 74 Search a 2D Matrix
python:class Solution: def searchMatrix(self, matrix, target): """ :type matrix: List[List[int]] :type target: int :rtype: bool """ if len(matrix) =...原创 2018-07-12 15:27:43 · 227 阅读 · 0 评论 -
leetcode 543 Diameter of Binary Tree
python:class Solution: def diameterOfBinaryTree(self, root): """ :type root: TreeNode :rtype: int """ if not root: return 0 self.long...原创 2018-07-17 21:26:05 · 182 阅读 · 0 评论 -
leetcode 168 Excel Sheet Column Title
python:class Solution: def convertToTitle(self, n): """ :type n: int :rtype: str """ ans = '' while n > 0: n = n - 1 j = ...原创 2018-06-03 21:07:24 · 175 阅读 · 0 评论 -
leetcode 263 Ugly Number
python:class Solution: def isUgly(self, num): """ :type num: int :rtype: bool """ if num == 1 : return True if num == 0: ret...原创 2018-06-04 16:05:06 · 172 阅读 · 0 评论 -
leetcode 746 Min Cost Climbing Stairs
python:class Solution: def minCostClimbingStairs(self, cost): """ :type cost: List[int] :rtype: int """ for i in range(2,len(cost)): cost[i] += ...原创 2018-06-11 16:46:04 · 177 阅读 · 0 评论 -
leetcode 205 Isomorphic Strings
python:class Solution: def isIsomorphic(self, s, t): """ :type s: str :type t: str :rtype: bool """ dic = dict() for i,j in zip(s,t): ...原创 2018-06-05 17:21:00 · 145 阅读 · 0 评论 -
leetcode 290 Word Pattern
python:class Solution(object): def wordPattern(self, pattern, str): """ :type pattern: str :type str: str :rtype: bool """ stlist = str.split() ...原创 2018-06-05 20:13:20 · 219 阅读 · 1 评论 -
leetcode 232 Implement Queue using Stacks
python:class MyQueue: def __init__(self): """ Initialize your data structure here. """ self.s1 = [] self.s2 = [] def push(self, x): """ ...原创 2018-06-22 12:41:16 · 190 阅读 · 0 评论 -
leetcode 283 Move Zeroes
python:class Solution: def moveZeroes(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """ i = 0 ...原创 2018-06-29 11:06:58 · 159 阅读 · 0 评论 -
leetcode 93 Restore IP Addresses
python:class Solution: def restoreIpAddresses(self, s): """ :type s: str :rtype: List[str] """ def dfs(s, index, path, res): if index == 4: ...原创 2018-06-25 11:18:15 · 193 阅读 · 0 评论 -
leetcode 16 3Sum Closest
C++:class Solution {public: int threeSumClosest(vector<int>& nums, int target) { sort(nums.begin(), nums.end()); int l, r; int res = INT_MAX; int ans = 0...原创 2018-06-20 15:49:58 · 288 阅读 · 0 评论 -
leetcode 189 Rotate Array
c++:class Solution {public: void rotate(vector<int>& nums, int k) { k = k % nums.size(); reverse(nums.begin(), nums.end()); reverse(nums.begin(), nums.begin() + ...原创 2018-06-20 17:19:50 · 124 阅读 · 0 评论 -
leetcode 189 Rotate Array
c++:class Solution {public: void rotate(vector<int>& nums, int k) { k = k % nums.size(); reverse(nums.begin(), nums.end()); reverse(nums.begin(), nums.begin() + ...原创 2018-06-20 17:20:16 · 146 阅读 · 0 评论 -
leetcode 485 Max Consecutive Ones
python:class Solution: def findMaxConsecutiveOnes(self, nums): """ :type nums: List[int] :rtype: int """ res = 0 l = 0 for i in nums: ...原创 2018-07-02 17:17:57 · 230 阅读 · 0 评论 -
leetcode 860 Lemonade Change
python:class Solution: def lemonadeChange(self, bills): """ :type bills: List[int] :rtype: bool """ mon = dict() mon[5] = 0 mon[10] = 0 ...原创 2018-07-16 19:31:57 · 251 阅读 · 0 评论 -
leetcode 35 Search Insert Position
python:class Solution: def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ t = 0 for index, i ...原创 2018-07-04 16:35:42 · 183 阅读 · 0 评论 -
leetcode 66 Plus One
python:class Solution: def plusOne(self, digits): """ :type digits: List[int] :rtype: List[int] """ res = [] t = 1 for i in digits[::-1]: ...原创 2018-07-05 11:04:19 · 208 阅读 · 0 评论 -
leetcode 637 Average of Levels in Binary Tree
python:class Solution: def averageOfLevels(self, root): """ :type root: TreeNode :rtype: List[float] """ if root is None: return [] r...原创 2018-10-24 11:10:35 · 269 阅读 · 0 评论