摘要:problem 541. Reverse String II 题意: 给定一个字符串,每隔k个字符翻转这k个字符,剩余的小于k个则全部翻转,否则还是只翻转剩余的前k个字符。 solution1: solution2: 简洁版 就是每2k个字符来遍历原字符串s,然后进行翻转,翻转的结尾位置是取i+k和
阅读全文
摘要:problem 538. Convert BST to Greater Tree 参考 1. Leetcode_easy_538. Convert BST to Greater Tree; 完
阅读全文
摘要:problem 532. K-diff Pairs in an Array 题意:统计有重复无序数组中差值为K的数对个数。 solution1: 使用映射关系; 统计数组中每个数字的个数。我们可以建立每个数字和其出现次数之间的映射,然后遍历哈希表中的数字,如果k为0且该数字出现的次数大于1,则结果r
阅读全文
摘要:problem 530. Minimum Absolute Difference in BST 参考 1. Leetcode_easy_530. Minimum Absolute Difference in BST; 2. Grandyang_二叉搜索树的最小绝对差; 完
阅读全文
摘要:problem 521. Longest Uncommon Subsequence I 最长非共同子序列之一 题意: 两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个字符串不等,那么较长的那个字符串就是最长非共同子序列。 solution: or 参考 1. Lee
阅读全文
摘要:problem 520. Detect Capital 题意: 题目中给出的三种情况,分别是全是大写、全是小写、首字母大写,这三种情况返回True;否则返回False; solution: 参考 1. Leetcode_520. Detect Capital; 完
阅读全文
摘要:problem 509. Fibonacci Number solution1: 递归调用 solution2: 结果只与前两个数字有关。 solution3: 使用数组类型数据。 但是不知道哪里有问题,为什么一直没有通过。。。哪位大神看到知道原因的麻烦告知一下下哈~ 参考 1. Leetcode_
阅读全文
摘要: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
阅读全文
摘要:problem 506. Relative Ranks solution1:使用优先队列; 掌握priority_queue 和 pair的使用; solution2: 使用映射map; 参考 1. Leetcode_506. Relative Ranks; 完
阅读全文
摘要:problem 504. Base 7 solution: 参考 1. Leetcode_504. Base 7; 完
阅读全文
摘要:problem 501. Find Mode in Binary Search Tree 参考 1. Leetcode_501. Find Mode in Binary Search Tree; 完
阅读全文
摘要:problem 500. Keyboard Row 题意:判断给出的某个单词是否可以使用键盘上的某一行字母type得到; 注意大小写的转换; solution1: 使用set保存三行字符,查看每个字符所在的行数是否一致; SET: or: 判断每一行的字母数目是否与对应单词的长度一致; class
阅读全文
摘要:problem: 496. Next Greater Element I 题意:求集合中每个数字在原数组中右边第一个较大的数字。 solution1: 暴力搜索; class Solution { public: vector<int> nextGreaterElement(vector<int>&
阅读全文
摘要:problem 492. Construct the Rectangle solution1: solution2: 参考 1. Leetcode_492. Construct the Rectangle; 2. GrandYang; 完
阅读全文
摘要:problem 485. Max Consecutive Ones solution1: 参考 1. Leetcode_485. Max Consecutive Ones; 完
阅读全文
摘要:problem 482. License Key Formatting solution1: 倒着处理,注意第一个字符为分隔符的情况要进行删除,注意字符的顺序是否正序。 参考 1. Leetcode_482. License Key Formatting; 2. GrandYang; 完
阅读全文
摘要:problem 476. Number Complement solution1: 参考 1. Leetcode_476. Number Complement; 2. GrandYang; 完
阅读全文
摘要:problem 475. Heaters solution1: 博主的理解就是计算每个house对应的能够cover到的最小值,注意两个数组有先进行排序哦,然后cover每个house的最小值中的最大值即为所求解的能够cover每个house的最小值。 参考 1. Leetcode_475. Hea
阅读全文
摘要:problem 463. Island Perimeter solution: 参考 1. Leetcode_463. Island Perimeter; 完
阅读全文
摘要:problem 461. Hamming Distance solution1: 根据题意,所求汉明距离指的是两个数字的二进制对应位不同的个数。对应位异或操作为1的累积和。 solution2: 两个数字异或之后,统计结果二进制中1的个数。 注意,两种solution都是移动 i 个位置。 参考 1
阅读全文