随笔分类 -  leetcode

【leetcode】459. Repeated Substring Pattern
摘要:problem 459. Repeated Substring Pattern solution1: 这道题给了我们一个字符串,问其是否能拆成n个重复的子串。那么既然能拆分成多个子串,那么每个子串的长度肯定不能大于原字符串长度的一半,那么我们可以从原字符串长度的一半遍历到1,如果当前长度能被总长度整 阅读全文

posted @ 2019-03-14 11:46 鹅要长大 阅读(264) 评论(0) 推荐(0)

【leetcode】455. Assign Cookies
摘要:problem 455. Assign Cookies solution1: 对小朋友的满意程度(也就是胃口)和当前cookies的大小分别进行排序,满足一个小朋友则加1;否则比较下一个cookie是否满足小朋友。记住前提是每个小朋友最多只能得到一个cookie.也就是贪婪算法。 solution2 阅读全文

posted @ 2019-03-14 11:13 鹅要长大 阅读(177) 评论(0) 推荐(0)

【leetcode】453. Minimum Moves to Equal Array Elements
摘要:problem 453. Minimum Moves to Equal Array Elements 相当于把不等于最小值的数字都减到最小值所需要次数的累加和。 solution1: 记得初始化,否则默认初始值是最小值。 solution2: 换一种思路,就是数组之和减去最小值乘以数组长度之积。 参 阅读全文

posted @ 2019-03-14 10:48 鹅要长大 阅读(161) 评论(0) 推荐(0)

【leetcode】448. Find All Numbers Disappeared in an Array
摘要:problem 448. Find All Numbers Disappeared in an Array solution: 参考 1. Leetcode_448. Find All Numbers Disappeared in an Array; 2. GrandYang; 完 阅读全文

posted @ 2019-03-13 15:46 鹅要长大 阅读(125) 评论(0) 推荐(0)

[leetcode]447. Number of Boomerangs
摘要:problem 447. Number of Boomerangs 也就是回旋镖的数量问题,以一个点为端点,若存在n个相等的点,那么就有两种情况可以构成三元数组,abc和acb是不同,也就是排列问题,有n(n-1)个。那么遍历每个点存在的三元数组求和即为所求。 re: 1. Leetcode_447 阅读全文

posted @ 2019-03-11 10:41 鹅要长大 阅读(216) 评论(0) 推荐(0)

【leetcode】443. String Compression
摘要:problem 443. String Compression a: ss ss solution1: class Solution { public: int compress(vector<char>& chars) { if(chars.empty()) return 0; string re 阅读全文

posted @ 2019-03-08 15:02 鹅要长大 阅读(226) 评论(0) 推荐(0)

【leetcode】441. Arranging Coins
摘要:problem 441. Arranging Coins solution1: solution2: solution3: 参考 1. Leetcode_441. Arranging Coins; 完 阅读全文

posted @ 2019-03-08 13:38 鹅要长大 阅读(197) 评论(0) 推荐(0)

【leetcode】438. Find All Anagrams in a String
摘要:problem 438. Find All Anagrams in a String solution1: class Solution { public: vector<int> findAnagrams(string s, string p) { if(s.empty()) return {}; 阅读全文

posted @ 2019-03-07 09:38 鹅要长大 阅读(226) 评论(0) 推荐(0)

【leetcode】437. Path Sum III
摘要:problem 437. Path Sum III 参考 1. Leetcode_437. Path Sum III; 完 阅读全文

posted @ 2019-03-06 09:20 鹅要长大 阅读(116) 评论(0) 推荐(0)

【leetcode】434. Number of Segments in a String
摘要:problem 434. Number of Segments in a String solution1: 当前字符不为空且前一个字符为空,或者字符串首字符不为空,则为一个分割串。利用的是每一个分割串的前一个字符为空的特性,注意第一个分割串。 参考 1. Leetcode_434. Number 阅读全文

posted @ 2019-03-05 20:21 鹅要长大 阅读(142) 评论(0) 推荐(0)

【leetcode】429. N-ary Tree Level Order Traversal
摘要:problem 429. N-ary Tree Level Order Traversal solution1:Iteration 参考 1. Leetcode_429. N-ary Tree Level Order Traversal; 完 阅读全文

posted @ 2019-03-05 19:59 鹅要长大 阅读(164) 评论(0) 推荐(0)

【leetcode】427. Construct Quad Tree
摘要:problem 427. Construct Quad Tree 参考 1. Leetcode_427. Construct Quad Tree; 完 阅读全文

posted @ 2019-03-05 19:42 鹅要长大 阅读(151) 评论(0) 推荐(0)

【leetcode】415. Add Strings
摘要:problem 415. Add Strings solution: 参考 1. Leetcode_415. Add Strings; 完 阅读全文

posted @ 2019-03-04 19:08 鹅要长大 阅读(273) 评论(0) 推荐(0)

【leetcode】414. Third Maximum Number
摘要:problem 414. Third Maximum Number solution 思路:用三个变量first, second, third来分别保存第一大、第二大和第三大的数,然后遍历数组。 注意: 1. 数据类型对应的最小值表示; 2. 赋值时需要判断是否为最小值; 参考 1. Leetcod 阅读全文

posted @ 2019-03-03 16:53 鹅要长大 阅读(215) 评论(0) 推荐(0)

【leetcode】412. Fizz Buzz
摘要:problem 412. Fizz Buzz solution: 参考 1. Leetcode_412. Fizz Buzz; 完 阅读全文

posted @ 2019-03-03 16:51 鹅要长大 阅读(185) 评论(0) 推荐(0)

【leetcode】409. Longest Palindrome
摘要:problem 409. Longest Palindrome solution1: 参考 1. Leetcode_409. Longest Palindrome; 完 阅读全文

posted @ 2019-03-03 16:43 鹅要长大 阅读(307) 评论(0) 推荐(0)

Guess
摘要:solution: 阅读全文

posted @ 2019-03-02 15:39 鹅要长大 阅读(234) 评论(0) 推荐(0)

【leetcode】Sum of Two Integers
摘要:problem Sum of Two Integers 不知道为什么一直出错; runtime error: left shift of negative value -2147483648 (solution.cpp) 参考 1. Leetcode_Sum of Two Integers; 完 不 阅读全文

posted @ 2019-03-01 11:47 鹅要长大 阅读(770) 评论(0) 推荐(0)

【leetcode】367. Valid Perfect Square
摘要:problem 367. Valid Perfect Square solution:二分法; solution2: 纯数学解法,利用到了这样一条性质,完全平方数是一系列奇数之和; 时间复杂度为O(sqrt(n)) 其他两种方法都出现超时的问题。 参考 1. Leetcode_367. Valid 阅读全文

posted @ 2019-03-01 10:16 鹅要长大 阅读(215) 评论(0) 推荐(0)

【leetcode】350. Intersection of Two Arrays II
摘要:problem 350. Intersection of Two Arrays II 不是特别明白这道题的意思,例子不够说明问题; 是按顺序把相同的元素保存下来,还是排序,但是第二个例子没有重复.... 参考 1. Leetcode_350. Intersection of Two Arrays I 阅读全文

posted @ 2019-02-25 12:44 鹅要长大 阅读(154) 评论(0) 推荐(0)

导航