突然很想刷刷题,LeetCode是一个不错的选择,忽略了输入输出,更好的突出了算法,省去了不少时间. dalao们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对应的随笔下面评论区留言,我会及时处理,在此谢过了. 过程或许会很漫长,也很痛苦,慢慢来吧. 编号 题名 过题率 难度 1 Two Sum 0.376 Easy 2 Add Two Numbers 0.285 Medium 3 Longest Substring Without Repeating C…
基础的 api 还是不够熟悉啊 5112. 十六进制魔术数字 class Solution { public: char *lltoa(long long num, char *str, int radix) { const char index[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; unsigned long long unum; int i = 0, j, k; if(radix == 10 && num <…
1566. 重复至少 K 次且长度为 M 的模式 #模拟 题目链接 题意 给定正整数数组 arr,请你找出一个长度为 m 且在数组中至少重复 k 次的模式. 模式 是由一个或多个值组成的子数组(连续的子序列),连续 重复多次但 不重叠 . 模式由其长度和重复次数定义.如果数组中存在至少重复 k 次且长度为 m 的模式,则返回 true ,否则返回 false . 分析 题目初看有点麻烦,但实际上隔着特定周期(即重复长度)去检查相应字符是否相等,模拟一下题意即可. class Solution {…
5629. 重新格式化电话号码 模拟 注意一些细节,最后位置是否取值. class Solution { public: string reformatNumber(string number) { string s; for (auto c: number) if (c != ' ' && c != '-') s += c; string res; for (int i = 0; i < s.size();) { if ((int)s.size() - i > 4) res…
今天做了三道LeetCode上的简单题目,每道题都是用c++和Python两种语言写的.由于c++版的代码网上比較多.所以就仅仅分享一下Python的代码吧,刚学完Python的基本的语法,做做LeetCode的题目还是不错的,对以后找工作面试也有帮助! 刚開始就从AC率最高的入手吧! 1.Given an array of integers, every element appears twice except for one. Find that single one. Note: Your…
581. Shortest Unsorted Continuous Subarray Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too. You need to find the shor…