Leetcode
Vincent_gc
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【Leetcode】Add digit
今天在Leetcode刷题的时候遇到一类新题:关于数根(digital root)的问题问题描述Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. 给定一个非负数,将它的各位加起来,得到的数继续加,直到最后剩下一位数为止。For example:原创 2017-04-01 14:10:25 · 593 阅读 · 0 评论 -
【Leetcode】740. Delete and Earn
Given an array nums of integers, you can perform operations on the array.In each operation, you pick any nums[i] and delete it to earn nums[i] points. After, you must delete every element equal to n...原创 2018-03-27 14:24:49 · 408 阅读 · 0 评论 -
【Leetcode】179. Largest Number
因为是列表中数字组合,所以第一反正是用回溯做: version 1 :class Solution: # @param {integer[]} nums # @return {string} def largestNumber(self, nums): res = [0] n = len(nums) def dfs(...原创 2018-03-26 21:24:29 · 196 阅读 · 0 评论 -
【Leetcode】811. Subdomain Visit Count
简单的字符串类型题目 Python做主要用到dict.get()和split()函数 version 1class Solution(object): def subdomainVisits(self, cpdomains): """ :type cpdomains: List[str] :rtype: List[str] ...原创 2018-04-01 13:52:50 · 452 阅读 · 0 评论 -
【Leetcode】228. Summary Ranges
判断连续数的范围,遍历判断,很简单: version 1:class Solution(object): def summaryRanges(self, nums): """ :type nums: List[int] :rtype: List[str] """原创 2018-03-21 23:26:26 · 221 阅读 · 0 评论 -
【Leetcode】650. 2 Keys Keyboard
利用动态规划的思路: 遍历1到n,如果是质数的话,操作次数为数的大小。非质数的操作次数则根据可整除的最大数决定。 version 1:class Solution(object): def minSteps(self, n): """ :type n: int :rtype: int ""&原创 2018-03-26 12:20:49 · 236 阅读 · 0 评论 -
【Leetcode】806. Number of Lines To Write String
这是leetcode contest 77的新题: 第一次参加contest,前边两道题确实简单。version 1:class Solution(object): def numberOfLines(self, widths, S): """ :type widths: List[int] :type S: str ...原创 2018-03-25 14:52:36 · 542 阅读 · 2 评论 -
【Leetcode】687. Longest Univalue Path
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution(object): d...原创 2018-03-14 17:14:28 · 220 阅读 · 0 评论 -
【Leetcode】718. Maximum Length of Repeated Subarray
动态规划里的最长公共子串问题 1.0代码class Solution(object): def findLength(self, A, B): """ :type A: List[int] :type B: List[int] :rtype: int "&amp原创 2018-03-19 22:42:03 · 200 阅读 · 0 评论 -
【Leetcode】386. Lexicographical Numbers
想到的是变成字符然后排序。 version 1 :def lexicalOrder(self, n): """ :type n: int :rtype: List[int] """ res=[] for i in range(n+1):原创 2018-03-23 15:09:33 · 199 阅读 · 0 评论 -
【Leetcode】131. Palindrome Partitioning
class Solution(object): def partition(self, s): """ :type s: str :rtype: List[List[str]] """ def dfs(s,index,p原创 2018-03-13 17:16:47 · 187 阅读 · 0 评论 -
【Leetcode】49. Group Anagrams
方法很好想,用哈希表来做。 只要将每个字符串排序后作为key就可以了class Solution(object): def groupAnagrams(self, strs): """ :type strs: List[str] :rtype: List[List[str]] """ dict = {}..原创 2018-03-14 23:00:36 · 206 阅读 · 0 评论 -
【Leetcode】238. Product of Array Except Self
原题不让用除法,也就是不能先把数组中所有元素乘起来然后对单个元素进行除法运算得到结果。 这样解决思路就是,针对某个值,先遍历之前的数乘起来,再遍历之后的数乘起来。两者想乘就是当前值对应的输出。Python代码:class Solution(object): def productExceptSelf(self, nums): """ :type num...原创 2018-06-28 21:17:35 · 220 阅读 · 0 评论
分享