![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
xingyu97
这个作者很懒,什么都没留下…
展开
-
[LeetCode]443. 压缩字符串 ★
每天一道编程题题目描述样例python解法C++语言解法题目描述给定一组字符,使用原地算法将其压缩。压缩后的长度必须始终小于或等于原数组长度。数组的每个元素应该是长度为1 的字符(不是 int 整数类型)。在完成原地修改输入数组后,返回数组的新长度。样例示例 1:输入:[“a”,“a”,“b”,“b”,“c”,“c”,“c”]输出:返回6,输入数组的前6个字符应该是:[“a”...原创 2019-11-24 19:30:00 · 140 阅读 · 0 评论 -
[LeetCode]441. 排列硬币
每天一道编程题题目描述样例python解法C++语言解法题目描述你总共有 n 枚硬币,你需要将它们摆成一个阶梯形状,第 k 行就必须正好有 k 枚硬币。给定一个数字 n,找出可形成完整阶梯行的总行数。n 是一个非负整数,并且在32位有符号整型的范围内。样例python解法class Solution: def arrangeCoins(self, n: int) ->...原创 2019-11-14 16:07:50 · 126 阅读 · 0 评论 -
[LeetCode]434. 字符串中的单词数 ★
每天一道编程题题目描述样例python解法C语言解法题目描述统计字符串中的单词个数,这里的单词指的是连续的不是空格的字符。请注意,你可以假定字符串里不包括任何不可打印的字符。样例输入: “Hello, my name is John”输出: 5注意:如果给的字符串中,标点符号两边有空格,那么标点符号也算是一个单词。python解法class Solution: def c...原创 2019-10-23 11:18:43 · 109 阅读 · 0 评论 -
[LeetCode]429. N叉树的层序遍历 ★
每天一道编程题题目描述样例python解法C语言解法题目描述给定一个 N 叉树,返回其节点值的层序遍历。 (即从左到右,逐层遍历)。例如,给定一个 3叉树 :样例返回其层序遍历:python解法"""# Definition for a Node.class Node: def __init__(self, val, children): self.v...原创 2019-10-23 11:04:12 · 177 阅读 · 0 评论 -
[LeetCode]258. Add Digits ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.题目大意:给定一个非负整数,重复计算它的各位数字之和,直到各位之和只有一个数字。样例Example:Input: 38Out...原创 2019-08-29 09:12:08 · 138 阅读 · 0 评论 -
[LeetCode]268. Missing Number ★
每天一道编程题题目描述样例python解法C语言解法题目描述题目大意:样例python解法class Solution: def missingNumber(self, nums: List[int]) -> int: req_sum = len(nums)*(len(nums)+1)/2 act_sum = sum(nums) ...原创 2019-08-29 09:12:24 · 99 阅读 · 0 评论 -
[LeetCode]242. Valid Anagram ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given two strings s and t , write a function to determine if t is an anagram of s.题目大意:给定两个字符串 s 和 t ,判断 t 是否是 s 中的字符变换顺序得到的。如果是返回True,否则返回False样例Example 1:Input: ...原创 2019-08-30 15:52:20 · 79 阅读 · 0 评论 -
[LeetCode]278. First Bad Version ★
每天一道编程题题目描述样例python解法C语言解法题目描述You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each v...原创 2019-08-31 09:32:54 · 100 阅读 · 0 评论 -
[LeetCode]283. Move Zeroes ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.题目大意:样例Example:Input: [0,1,0,3...原创 2019-09-01 09:06:01 · 81 阅读 · 0 评论 -
[LeetCode]290. Word Pattern ★
每天一道编程题题目描述样例python解法题目描述Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-...原创 2019-09-01 09:06:14 · 92 阅读 · 0 评论 -
[LeetCode]263. Ugly Number ★
每天一道编程题题目描述样例python解法C语言解法题目描述Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.题目大意:判断一个数是否是丑数,丑数的定义就是一个...原创 2019-08-28 17:58:10 · 95 阅读 · 0 评论 -
[LeetCode]257. Binary Tree Paths ★
每天一道编程题题目描述样例python解法C语言解法题目描述题目大意:样例python解法# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.r...原创 2019-08-28 09:22:59 · 67 阅读 · 0 评论 -
[LeetCode]237. Delete Node in a Linked List ★
每天一道编程题题目描述样例python解法C语言解法题目描述Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Given linked list – head = [4,5,1,9], which looks like foll...原创 2019-08-27 09:00:26 · 90 阅读 · 0 评论 -
[LeetCode]232. Implement Queue using Stacks ★
每天一道编程题题目描述样例python解法C语言解法题目描述Implement the following operations of a queue using stacks.push(x) – Push element x to the back of queue.pop() – Removes the element from in front of queue.peek() – ...原创 2019-08-27 09:00:15 · 118 阅读 · 0 评论 -
[LeetCode]231. Power of Two ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given an integer, write a function to determine if it is a power of two.题目大意:给定一个数字,判断该数是不是2的n次幂样例Example 1:Input: 1Output: trueExplanation: 20 = 1Example 2:...原创 2019-08-26 17:25:59 · 92 阅读 · 0 评论 -
[LeetCode]226. Invert Binary Tree ★
每天一道编程题题目描述样例python解法C语言解法题目描述Invert a binary tree.题目大意:交换二叉树的左右子树样例Example:Input:Output:python解法# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# ...原创 2019-08-26 17:25:45 · 95 阅读 · 0 评论 -
[LeetCode]205. Isomorphic Strings ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character ...原创 2019-08-23 09:40:11 · 141 阅读 · 0 评论 -
[LeetCode]111. Minimum Depth of Binary Tree★
每天一道编程题题目描述样例python解法C语言解法题目描述Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Note: A ...原创 2019-08-18 09:11:16 · 84 阅读 · 0 评论 -
[LeetCode]303. Range Sum Query - Immutable ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.题目大意:给定一个数字数组,计算其中下标从 i 到 j 的元素的和,i,j 均合法且为闭区间。样例Example:Given...原创 2019-09-01 21:49:30 · 94 阅读 · 0 评论 -
[LeetCode]326. Power of Three ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given an integer, write a function to determine if it is a power of three.题目大意:给定一个整数,判断这个整数是否是3的n次幂样例Example 1:Input: 27Output: trueExample 2:Input: 0Outpu...原创 2019-09-02 08:55:29 · 92 阅读 · 0 评论 -
[LeetCode]344. Reverse String ★
每天一道编程题题目描述样例python解法C语言解法题目描述Write a function that reverses a string. The input string is given as an array of characters char[].Do not allocate extra space for another array, you must do this by ...原创 2019-09-04 09:12:55 · 82 阅读 · 0 评论 -
[LeetCode]415. 字符串相加 ★
每天一道编程题题目描述样例python解法C语言解法题目描述给定两个字符串形式的非负整数 num1 和num2 ,计算它们的和。注意:num1 和num2 的长度都小于 5100.num1 和num2 都只包含数字 0-9.num1 和num2 都不包含任何前导零。你不能使用任何內建 BigInteger 库, 也不能直接将输入的字符串转换为整数形式。样例无python解法c...原创 2019-10-11 15:39:03 · 314 阅读 · 0 评论 -
[LeetCode]414. 第三大的数 ★
每天一道编程题题目描述样例python解法C语言解法题目描述给定一个非空数组,返回此数组中第三大的数。如果不存在,则返回数组中最大的数。要求算法时间复杂度必须是O(n)。样例示例 1:输入: [3, 2, 1]输出: 1解释: 第三大的数是 1.示例 2:输入: [1, 2]输出: 2解释: 第三大的数不存在, 所以返回最大的数 2 .示例 3:输入: [2, ...原创 2019-10-10 20:25:46 · 105 阅读 · 0 评论 -
[LeetCode]412. Fizz Buzz ★
每天一道编程题题目描述样例python解法C语言解法题目描述写一个程序,输出从 1 到 n 数字的字符串表示。如果 n 是3的倍数,输出“Fizz”;如果 n 是5的倍数,输出“Buzz”;如果 n 同时是3和5的倍数,输出 “FizzBuzz”。样例n = 15,返回:[“1”,“2”,“Fizz”,“4”,“Buzz”,“Fizz”,“7”,“...原创 2019-10-10 20:16:28 · 130 阅读 · 0 评论 -
[LeetCode]405. 数字转换为十六进制数 ★
每天一道编程题题目描述样例python解法C语言解法题目描述给定一个整数,编写一个算法将这个数转换为十六进制数。对于负整数,我们通常使用 补码运算 方法。注意:十六进制中所有字母(a-f)都必须是小写。十六进制字符串中不能包含多余的前导零。如果要转化的数为0,那么以单个字符’0’来表示;对于其他情况,十六进制字符串中的第一个字符将不会是0字符。给定的数确保在32位有符号整数范围内。...原创 2019-10-06 11:26:34 · 189 阅读 · 0 评论 -
[LeetCode]404. 左叶子之和 ★
每天一道编程题题目描述样例python解法C语言解法题目描述计算给定二叉树的所有左叶子之和。样例python解法# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# ...原创 2019-10-03 16:23:05 · 207 阅读 · 0 评论 -
[LeetCode]401. 二进制手表 ★
每天一道编程题题目描述样例python解法C语言解法题目描述二进制手表顶部有 4 个 LED 代表小时(0-11),底部的 6 个 LED 代表分钟(0-59)。每个 LED 代表一个 0 或 1,最低位在右侧。样例输入: n = 1返回: [“1:00”, “2:00”, “4:00”, “8:00”, “0:01”, “0:02”, “0:04”, “0:08”, “0:16”,...原创 2019-10-02 16:49:45 · 124 阅读 · 0 评论 -
[LeetCode]392. 判断子序列 ★
每天一道编程题题目描述样例python解法C语言解法题目描述给定字符串 s 和 t ,判断 s 是否为 t 的子序列。你可以认为 s 和 t 中仅包含英文小写字母。字符串 t 可能会很长(长度 ~= 500,000),而 s 是个短字符串(长度 <=100)。字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串。(例如,"ace"是"abc...原创 2019-09-29 16:01:50 · 80 阅读 · 0 评论 -
[LeetCode]389. 找不同 ★
每天一道编程题题目描述样例python解法C语言解法题目描述给定两个字符串 s 和 t,它们只包含小写字母。字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。请找出在 t 中被添加的字母。样例输入:s = “abcd”t = “abcde”输出:e解释:‘e’ 是那个被添加的字母。输入:s = “a”t = “aa”输出:apython解法cla...原创 2019-09-28 16:04:45 · 172 阅读 · 0 评论 -
[LeetCode]387. 字符串中的第一个唯一字符 ★
每天一道编程题题目描述样例python解法C语言解法题目描述给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。样例s = “leetcode”返回 0.s = “loveleetcode”,返回 2.python解法class Solution: def firstUniqChar(self, s: str) -> int: ...原创 2019-09-27 15:01:05 · 76 阅读 · 0 评论 -
[LeetCode]383. Ransom Note ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be con...原创 2019-09-07 09:35:25 · 224 阅读 · 0 评论 -
[LeetCode]374. Guess Number Higher or Lower ★
每天一道编程题题目描述样例python解法C++语言解法题目描述We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I’ll tell you...原创 2019-09-07 09:35:08 · 163 阅读 · 0 评论 -
[LeetCode]367. 有效的完全平方数 ★
每天一道编程题题目描述样例python解法C语言解法题目描述给定一个正整数 num,编写一个函数,如果 num 是一个完全平方数,则返回 True,否则返回 False。说明:不要使用任何内置的库函数,如 sqrt。样例示例 1:输入:16输出:True示例 2:输入:14输出:Falsepython解法class Solution: def isPerf...原创 2019-09-05 09:06:50 · 160 阅读 · 0 评论 -
[LeetCode]350. Intersection of Two Arrays II ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given two arrays, write a function to compute their intersection.题目大意:求两个数组的全部交集,重复的也算样例Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2,2]Example 2:...原创 2019-09-05 09:06:31 · 106 阅读 · 0 评论 -
[LeetCode]349. Intersection of Two Arrays ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given two arrays, write a function to compute their intersection.题目大意:求两个给定集合的交集样例Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2]Example 2:Input:...原创 2019-09-04 09:13:08 · 122 阅读 · 0 评论 -
[LeetCode]203. Remove Linked List Elements ★
每天一道编程题题目描述样例python解法C语言解法题目描述题目大意:样例python解法# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution:...原创 2019-08-22 15:42:28 · 97 阅读 · 0 评论 -
[LeetCode]136. Single Number ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Cou...原创 2019-08-17 08:40:58 · 64 阅读 · 0 评论 -
[LeetCode]202. Happy Number ★
每天一道编程题题目描述样例python解法C语言解法题目描述Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the num...原创 2019-08-22 09:27:43 · 112 阅读 · 0 评论 -
[LeetCode]104. Maximum Depth of Binary Tree ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A ...原创 2019-08-14 08:47:03 · 180 阅读 · 0 评论 -
[LeetCode]101. Symmetric Tree ★
每天一道编程题题目描述样例python解法C语言解法题目描述Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric:But the foll...原创 2019-08-13 20:44:47 · 81 阅读 · 0 评论