【Leetcode周赛】从contest1开始。(一般是10个contest写一篇文章)
注意,以前的比赛我是自己开了 virtual contest。这个阶段的目标是加快手速,思考问题的能力和 bug-free 的能力。
前面已经有了100个contest。计划是每周做三个到五个contest。每次计算时间一个半小时。
Warm Up Contest (Contest 1)(2018年10月22日,周一)
链接:https://leetcode.com/contest/warm-up-contest
【386】Lexicographical Numbers
给了一个数字 n,要求返回 1 ~ n的字典顺排序。
For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].
题解:我一开始用了转成字符串然后用字符串比较的方式排序,但是不行,tle。后来直接dfs自己生成,AC了。
//转成字符串排序会tle
class Solution {
public:
vector<int> lexicalOrder(int n) {
vector<int> ans;
if (n <= ) {
return ans;
}
dfs(n, , ans);
return ans;
}
void dfs(int n, int temp, vector<int>& ans) {
for (int cur = ; cur <= ; ++cur) {
if (temp == && cur == ) { continue; }
temp = temp * + cur;
if (temp <= n) {
if (temp != ) {ans.push_back(temp);}
dfs(n, temp, ans);
temp = (temp - cur) / ; //backtracking 这个要调。
} else {
return;
}
}
}
};
【387】First Unique Character in a String
给了一个字符串,要求返回第一个出现只一次字符的下标,不存在这样的字符返回 -1。
题解:直接用了一个map,能过。
class Solution {
public:
int firstUniqChar(string s) {
const int n = s.size();
if (n == ) {return -;}
map<char, vector<int>> mp;
for (int i = ; i < n; ++i) {
mp[s[i]].push_back(i);
}
int ans = n;
for (auto ele : mp) {
if (ele.second.size() == ) {
ans = min(ans, ele.second.front());
}
}
return ans == n ? - : ans;
}
};
【388】Longest Absolute File Path
Contest 2(2018年10月23日,周二)
链接:https://leetcode.com/contest/leetcode-weekly-contest-2
【389】Find the Difference
【390】Elimination Game
【391】Perfect Rectangle
【Leetcode周赛】从contest1开始。(一般是10个contest写一篇文章)的更多相关文章
- 【Leetcode周赛】从contest-111开始。(一般是10个contest写一篇文章)
Contest 111 (题号941-944)(2019年1月19日,补充题解,主要是943题) 链接:https://leetcode.com/contest/weekly-contest-111 ...
- 【Leetcode周赛】从contest-71开始。(一般是10个contest写一篇文章)
Contest 71 () Contest 72 () Contest 73 (2019年1月30日模拟) 链接:https://leetcode.com/contest/weekly-contest ...
- 【Leetcode周赛】从contest-81开始。(一般是10个contest写一篇文章)
Contest 81 (2018年11月8日,周四,凌晨) 链接:https://leetcode.com/contest/weekly-contest-81 比赛情况记录:结果:3/4, ranki ...
- 【Leetcode周赛】从contest-91开始。(一般是10个contest写一篇文章)
Contest 91 (2018年10月24日,周三) 链接:https://leetcode.com/contest/weekly-contest-91/ 模拟比赛情况记录:第一题柠檬摊的那题6分钟 ...
- 【Leetcode周赛】从contest-121开始。(一般是10个contest写一篇文章)
Contest 121 (题号981-984)(2019年1月27日) 链接:https://leetcode.com/contest/weekly-contest-121 总结:2019年2月22日 ...
- 【Leetcode周赛】从contest-41开始。(一般是10个contest写一篇文章)
Contest 41 ()(题号) Contest 42 ()(题号) Contest 43 ()(题号) Contest 44 (2018年12月6日,周四上午)(题号653—656) 链接:htt ...
- 【Leetcode周赛】从contest-51开始。(一般是10个contest写一篇文章)
Contest 51 (2018年11月22日,周四早上)(题号681-684) 链接:https://leetcode.com/contest/leetcode-weekly-contest-51 ...
- 【LeetCode】从contest-21开始。(一般是10个contest写一篇文章)
[LeetCode Weekly Contest 29][2017/04/23] 第17周 Binary Tree Tilt (3) Array Partition I (6) Longest Lin ...
- LeetCode 31:递归、回溯、八皇后、全排列一篇文章全讲清楚
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天我们讲的是LeetCode的31题,这是一道非常经典的问题,经常会在面试当中遇到.在今天的文章当中除了关于题目的分析和解答之外,我们还会 ...
随机推荐
- Makefile总结(转帖)
文章地址:http://www.cnitblog.com/textbox/archive/2009/10/21/62036.aspx makefile 主要包含以下几点 显式规则 :描述了在何种情况 ...
- unittest接口自动化测试报告
unittest接口自动化测试报告 展示: 代码: __author__ = "Wai Yip Tung, Findyou" __version__ = "0.8.2.1 ...
- CSS 3D 的魅力
作者 | 子慕大诗人 来源 | www.cnblogs.com/1wen/p/9064011.html 前言: 最近玩了玩用css来构建3D效果,写了几个demo,所以博客总结一下. 在阅读 ...
- javax.net.ssl.SSLKeyException: RSA premaster secret error
环境jdk1.7, 调用第三方接口时,出现javax.net.ssl.SSLKeyException: RSA premaster secret error错误,解决方案,将jre/lib/ext所有 ...
- Anaconda基本命令
创建环境 conda create --name bunnies python=3 astroid babel 列出所有环境 conda info --envs 或 conda env list 克隆 ...
- Quartz.Net 任务调度之特性(3)
再实现类中使用,就是继承IJob的类 [PersistJobDataAfterExecution] //执行后的保留作业数据,链式传参(上一次的任务数据) [DisallowConcurrentExe ...
- Delphi ini文件操作 TIniFile、TMemIniFile
1.使用TIniFile unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Co ...
- SpringDataJpa全部依赖
<properties> <spring.version>4.2.4.RELEASE</spring.version> <hibernate.version& ...
- boost scope exit
Boost.ScopeExit provides the macro BOOST_SCOPE_EXIT, which can be used to define something that look ...
- subsequence 1
题目链接 题意:给你两个字符串都是数字,让你求第一个字符串的子序列中大于第二个字符串的个数. 思路:dp[i][j] 表示 str1的前i个,匹配 str2的前 j 个的种类数,那么 if(s[i] ...