![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
oj简单题
mysterious_i
这个作者很懒,什么都没留下…
展开
-
输出最小整数对,以第一个数为主键
/*题目描述:第一行输入一个数n,1 <= n <= 1000,下面输入n行数据,每一行有两个数,分别是x y。输出一组x y,该组数据是所有数据中x最小,且在x相等的情况下y最小的。输入:输入有多组数据。每组输入n,然后输入n个整数对。输出:输出最小的整数对。样例输入:53 32 25 52 13 6*/#include #include using names原创 2017-10-12 17:08:29 · 268 阅读 · 0 评论 -
Leetcode 20: Valid Parentheses
//括号匹配是典型的出栈入栈问题class Solution {public: bool isValid(string s) { vector<char> stack; if(s.length() <= 1 ) return false; while(s.length() > 0) ...原创 2018-03-30 09:31:39 · 102 阅读 · 0 评论 -
Leetcode 205: Isomorphic Strings
// 寻找对称的单词,一个简单的思路是遍历第一个字符串,将每一个字母出现的位置组合成一个int数值,如egg中g为12,并存为哈希表,最后比较两个哈希表中每个对应字母的int数值是否相同。class Solution {public: bool isIsomorphic(string s, string t) { if (s.length() != t.length()) re...原创 2018-03-25 11:17:18 · 117 阅读 · 0 评论 -
Leetcode 290: word sum
// 此题需要注意的是,哈希表在存储的时候插入顺序可能是随机的,如果此时要求两个表的key的相应位置一一对应不可行,需要以value为键值再建一个表 class Solution {public: bool wordPattern(string pattern, string str) { vector<string> str_vec; while (str.find('...原创 2018-03-25 21:29:10 · 92 阅读 · 0 评论 -
Leetcode 38: Count and Say
// 利用递归,需要注意最后一个数不能忘了加进去1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as "one 2, then one 1" or 1211.class Solution {public: string countAndSay(int n) { i...原创 2018-03-28 11:20:49 · 118 阅读 · 0 评论 -
Leetcode 67: Add Binary
//字符串的输入可能会是比较大的数组,需要用字符串逐位相加class Solution {public: string addBinary(string a, string b) { string result = ""; int max_length = a.length() > b.length() ? a.length() : b.length(); int min_l...原创 2018-03-28 16:43:47 · 106 阅读 · 0 评论