摘要: 题目 https://leetcode-cn.com/problems/longest-palindrome/ 解法 先理解回文串的定义 假设有 m 对字符,根据回文串的定义可得 全部两两成对之后,那就是 2*m 非两两成对,最后可以在中间放一个,那就是 2*m + 1 class Solution 阅读全文
posted @ 2021-07-15 23:44 吴丹阳-V 阅读(28) 评论(0) 推荐(0) 编辑
摘要: 题目 https://leetcode-cn.com/problems/convert-a-number-to-hexadecimal/ 解法 要处理一下负数,算出反码之后再进行转换进制 除以 16 取整,使用了一个小技巧:$num >>= 4; class Solution { private $ 阅读全文
posted @ 2021-07-15 23:38 吴丹阳-V 阅读(44) 评论(0) 推荐(0) 编辑
摘要: 题目 https://leetcode-cn.com/problems/sum-of-left-leaves/ 解法 树的遍历,so easy /** * Definition for a binary tree node. * class TreeNode { * public $val = nu 阅读全文
posted @ 2021-07-15 23:35 吴丹阳-V 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 题目 https://leetcode-cn.com/problems/reverse-vowels-of-a-string/ 解法 双指针 666 来全场跟我左边画条龙,右边跟我画一道彩虹 class Solution { const VOWELS = ['a' => 1, 'e' => 1, ' 阅读全文
posted @ 2021-07-15 23:32 吴丹阳-V 阅读(42) 评论(0) 推荐(0) 编辑
摘要: 题目 题目 https://leetcode-cn.com/problems/word-frequency/ 一行命令搞定 解法 grep -oP "\w+" words.txt | sort | uniq -c | sort -nrk1 | awk '{print $2 " " $1}' 阅读全文
posted @ 2021-07-15 23:24 吴丹阳-V 阅读(44) 评论(0) 推荐(0) 编辑