随笔分类 -  leetcode

【leetcode_easy】541. Reverse String II
摘要:problem 541. Reverse String II 题意: 给定一个字符串,每隔k个字符翻转这k个字符,剩余的小于k个则全部翻转,否则还是只翻转剩余的前k个字符。 solution1: solution2: 简洁版 就是每2k个字符来遍历原字符串s,然后进行翻转,翻转的结尾位置是取i+k和 阅读全文

posted @ 2019-05-29 10:29 鹅要长大 阅读(153) 评论(0) 推荐(0)

【leetcode_easy】538. Convert BST to Greater Tree
摘要:problem 538. Convert BST to Greater Tree 参考 1. Leetcode_easy_538. Convert BST to Greater Tree; 完 阅读全文

posted @ 2019-05-29 10:22 鹅要长大 阅读(149) 评论(0) 推荐(0)

【leetcode_easy】532. K-diff Pairs in an Array
摘要:problem 532. K-diff Pairs in an Array 题意:统计有重复无序数组中差值为K的数对个数。 solution1: 使用映射关系; 统计数组中每个数字的个数。我们可以建立每个数字和其出现次数之间的映射,然后遍历哈希表中的数字,如果k为0且该数字出现的次数大于1,则结果r 阅读全文

posted @ 2019-05-28 09:31 鹅要长大 阅读(196) 评论(0) 推荐(0)

【leetcode_easy】530. Minimum Absolute Difference in BST
摘要:problem 530. Minimum Absolute Difference in BST 参考 1. Leetcode_easy_530. Minimum Absolute Difference in BST; 2. Grandyang_二叉搜索树的最小绝对差; 完 阅读全文

posted @ 2019-05-27 14:01 鹅要长大 阅读(153) 评论(0) 推荐(0)

【leetcode】521. Longest Uncommon Subsequence I
摘要:problem 521. Longest Uncommon Subsequence I 最长非共同子序列之一 题意: 两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个字符串不等,那么较长的那个字符串就是最长非共同子序列。 solution: or 参考 1. Lee 阅读全文

posted @ 2019-05-27 13:48 鹅要长大 阅读(143) 评论(0) 推荐(0)

【leetcode】520. Detect Capital
摘要:problem 520. Detect Capital 题意: 题目中给出的三种情况,分别是全是大写、全是小写、首字母大写,这三种情况返回True;否则返回False; solution: 参考 1. Leetcode_520. Detect Capital; 完 阅读全文

posted @ 2019-05-27 13:32 鹅要长大 阅读(204) 评论(0) 推荐(0)

【leetcode】509. Fibonacci Number
摘要:problem 509. Fibonacci Number solution1: 递归调用 solution2: 结果只与前两个数字有关。 solution3: 使用数组类型数据。 但是不知道哪里有问题,为什么一直没有通过。。。哪位大神看到知道原因的麻烦告知一下下哈~ 参考 1. Leetcode_ 阅读全文

posted @ 2019-05-26 12:21 鹅要长大 阅读(189) 评论(0) 推荐(0)

【leetcode】507. Perfect Number
摘要:problem 507. Perfect Number solution: /* class Solution { public: bool checkPerfectNumber(int num) { int sum = 1; for(int i=2; i*i<=num; i++) { if(num 阅读全文

posted @ 2019-05-26 11:53 鹅要长大 阅读(188) 评论(0) 推荐(0)

【leetcode】506. Relative Ranks
摘要:problem 506. Relative Ranks solution1:使用优先队列; 掌握priority_queue 和 pair的使用; solution2: 使用映射map; 参考 1. Leetcode_506. Relative Ranks; 完 阅读全文

posted @ 2019-05-26 11:11 鹅要长大 阅读(162) 评论(0) 推荐(0)

【leetcode】504. Base 7
摘要:problem 504. Base 7 solution: 参考 1. Leetcode_504. Base 7; 完 阅读全文

posted @ 2019-05-24 17:27 鹅要长大 阅读(161) 评论(0) 推荐(0)

【leetcode】501. Find Mode in Binary Search Tree
摘要:problem 501. Find Mode in Binary Search Tree 参考 1. Leetcode_501. Find Mode in Binary Search Tree; 完 阅读全文

posted @ 2019-05-24 17:02 鹅要长大 阅读(119) 评论(0) 推荐(0)

【leetcode】500_Keyboard Row
摘要:problem 500. Keyboard Row 题意:判断给出的某个单词是否可以使用键盘上的某一行字母type得到; 注意大小写的转换; solution1: 使用set保存三行字符,查看每个字符所在的行数是否一致; SET: or: 判断每一行的字母数目是否与对应单词的长度一致; class 阅读全文

posted @ 2019-05-24 16:58 鹅要长大 阅读(253) 评论(0) 推荐(0)

【leetcode】496. Next Greater Element I
摘要:problem: 496. Next Greater Element I 题意:求集合中每个数字在原数组中右边第一个较大的数字。 solution1: 暴力搜索; class Solution { public: vector<int> nextGreaterElement(vector<int>& 阅读全文

posted @ 2019-05-16 09:45 鹅要长大 阅读(256) 评论(0) 推荐(0)

【leetcode】492. Construct the Rectangle
摘要:problem 492. Construct the Rectangle solution1: solution2: 参考 1. Leetcode_492. Construct the Rectangle; 2. GrandYang; 完 阅读全文

posted @ 2019-03-29 19:07 鹅要长大 阅读(181) 评论(0) 推荐(0)

【leetcode】485. Max Consecutive Ones
摘要:problem 485. Max Consecutive Ones solution1: 参考 1. Leetcode_485. Max Consecutive Ones; 完 阅读全文

posted @ 2019-03-29 18:18 鹅要长大 阅读(160) 评论(0) 推荐(0)

【leetcode】482. License Key Formatting
摘要:problem 482. License Key Formatting solution1: 倒着处理,注意第一个字符为分隔符的情况要进行删除,注意字符的顺序是否正序。 参考 1. Leetcode_482. License Key Formatting; 2. GrandYang; 完 阅读全文

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

【leetcode】476. Number Complement
摘要:problem 476. Number Complement solution1: 参考 1. Leetcode_476. Number Complement; 2. GrandYang; 完 阅读全文

posted @ 2019-03-24 19:58 鹅要长大 阅读(146) 评论(0) 推荐(0)

【leetcode】475. Heaters
摘要:problem 475. Heaters solution1: 博主的理解就是计算每个house对应的能够cover到的最小值,注意两个数组有先进行排序哦,然后cover每个house的最小值中的最大值即为所求解的能够cover每个house的最小值。 参考 1. Leetcode_475. Hea 阅读全文

posted @ 2019-03-21 09:27 鹅要长大 阅读(216) 评论(0) 推荐(0)

【leetcode】463. Island Perimeter
摘要:problem 463. Island Perimeter solution: 参考 1. Leetcode_463. Island Perimeter; 完 阅读全文

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

【leetcode】461. Hamming Distance
摘要:problem 461. Hamming Distance solution1: 根据题意,所求汉明距离指的是两个数字的二进制对应位不同的个数。对应位异或操作为1的累积和。 solution2: 两个数字异或之后,统计结果二进制中1的个数。 注意,两种solution都是移动 i 个位置。 参考 1 阅读全文

posted @ 2019-03-20 15:59 鹅要长大 阅读(190) 评论(0) 推荐(0)

导航