集合
HashMap,HashSet 等各类集合
csdnzhaocsdn
先通俗易懂
再简洁高效
菜但步履不停
所有文章只是学习用没有任何商业盈利若侵权我删
展开
-
347. 前 K 个高频元素
给定一个非空的整数数组,返回其中出现频率前 k 高的元素。示例 1:输入: nums = [1,1,1,2,2,3], k = 2输出: [1,2]示例 2:输入: nums = [1], k = 1输出: [1]说明:你可以假设给定的 k 总是合理的,且 1 ≤ k ≤ 数组中不相同的元素的个数。你的算法的时间复杂度必须优于 O(n log n) , n 是数组的大小。来源:...原创 2020-02-16 22:13:13 · 64 阅读 · 0 评论 -
215. 数组中的第K个最大元素
在未排序的数组中找到第 k 个最大的元素。请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素。示例 1:输入: [3,2,1,5,6,4] 和 k = 2输出: 5示例 2:输入: [3,2,3,1,2,4,5,5,6] 和 k = 4输出: 4来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/kth...原创 2020-02-16 12:16:16 · 67 阅读 · 0 评论 -
345. 反转字符串中的元音字母
编写一个函数,以字符串作为输入,反转该字符串中的元音字母。示例 1:输入: “hello”输出: “holle”示例 2:输入: “leetcode”输出: “leotcede”说明:元音字母不包含字母"y"。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/reverse-vowels-of-a-string著作权归领扣网...原创 2020-02-15 11:33:18 · 60 阅读 · 0 评论 -
270. Closest Binary Search Tree Value
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividing dividend by divisor.The integer division shoul...原创 2020-02-12 12:28:31 · 74 阅读 · 0 评论 -
142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-in...原创 2020-02-05 15:06:18 · 80 阅读 · 0 评论 -
2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...原创 2020-02-04 10:16:32 · 62 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Example 1:Input: “abcabcbb”Output: 3Explanation: The answer is “abc”, with the length of 3.Example 2:Input: ...原创 2020-02-02 17:05:38 · 47 阅读 · 0 评论 -
141. 环形链表
给定一个链表,判断链表中是否有环。为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos 是 -1,则在该链表中没有环。示例 1:输入:head = [3,2,0,-4], pos = 1输出:true解释:链表中有一个环,其尾部连接到第二个节点。示例 2:输入:head = [1,2], pos = 0输出:true解释...原创 2020-02-02 10:40:28 · 49 阅读 · 0 评论 -
242. 有效的字母异位词
给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。示例 1:输入: s = “anagram”, t = “nagaram”输出: true示例 2:输入: s = “rat”, t = “car”输出: false说明:你可以假设字符串只包含小写字母。进阶:如果输入字符串包含 unicode 字符怎么办?你能否调整你的解法来应对这种情况?来源:...原创 2020-01-29 18:44:26 · 39 阅读 · 0 评论 -
205. Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another ch...原创 2020-01-29 18:15:54 · 49 阅读 · 0 评论 -
202. Happy Number
Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of...原创 2020-01-29 17:13:41 · 48 阅读 · 0 评论 -
136. Single Number
Given a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usin...原创 2020-01-29 16:32:58 · 62 阅读 · 0 评论 -
219. 存在重复元素 II
给定一个整数数组和一个整数 k,判断数组中是否存在两个不同的索引 i 和 j,使得 nums [i] = nums [j],并且 i 和 j 的差的绝对值最大为 k。示例 1:输入: nums = [1,2,3,1], k = 3输出: true示例 2:输入: nums = [1,0,1,1], k = 1输出: true示例 3:输入: nums = [1,2,3,1,2,3]...原创 2020-01-28 16:12:27 · 54 阅读 · 0 评论 -
217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return false if every element is...原创 2020-01-28 15:49:19 · 58 阅读 · 0 评论 -
169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element alway...原创 2020-01-28 15:24:00 · 33 阅读 · 0 评论 -
1087 有多少不同的值 (20 分)
set#include <iostream>#include <set>using namespace std;int main() { int n; cin>>n; set<int> st; for(int i=1;i<=n;i++){ int m=i/2+i/3+i/5; st.insert(m); } ...原创 2018-12-07 22:06:46 · 119 阅读 · 0 评论 -
1090 危险品装箱 (25 分)
转载自柳神的博客:https://www.liuchuo.net/archives/6509 填上自个的一点理解。#include <iostream>#include <cstdio>#include <vector>#include <map>using namespace std;int main() {// freo...转载 2018-12-07 16:46:10 · 266 阅读 · 0 评论 -
1068 万绿丛中一点红 (20 分)
要点:①map的使用 ②PAT还是得注意格式问题:“在一行中按照 (x, y): color 的格式”不仅冒号和color之间有空格,逗号和y之间也有空格。#include <iostream>#include <map>#include <cmath>using namespace std;int m,n,tol;in...原创 2018-11-23 10:09:07 · 109 阅读 · 0 评论 -
1089 狼人杀-简单版 (20 分)
#include <iostream>#include <vector>#include <cmath>using namespace std;int main() { int n; cin>>n; int a[n+1]; for(int i=1;i<=n;i++){ cin>>a[i]; } fo...原创 2018-12-07 22:00:05 · 115 阅读 · 0 评论 -
1075 链表元素分类 (25 分)
#include <iostream>#include <cstdio>#include <vector>using namespace std;struct List{ int data; int next;};int main(){ int first,n,k; cin>>first>&...原创 2018-11-26 09:15:16 · 259 阅读 · 0 评论 -
1025 反转链表 (25 分)
24'。最后一个测试点没过,有大佬可以指出则磕头跪谢。 #include <iostream>#include <cstdio>#include <vector>using namespace std;struct List{ int data; int next;};int main(){ int first,...原创 2018-11-24 11:30:29 · 100 阅读 · 0 评论