上一页 1 2 3 4 5 6 7 8 9 ··· 38 下一页
摘要: 题目: 解答: 方法一:哈希 1 class Solution { 2 public: 3 vector<int> singleNumber(vector<int>& nums) { 4 map<int, int> count; 5 for (int n : nums) count[n] ++; 6 阅读全文
posted @ 2020-05-09 19:19 梦醒潇湘 阅读(166) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : 阅读全文
posted @ 2020-05-09 19:08 梦醒潇湘 阅读(166) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : 阅读全文
posted @ 2020-05-09 19:05 梦醒潇湘 阅读(122) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : 阅读全文
posted @ 2020-05-09 19:02 梦醒潇湘 阅读(152) 评论(0) 推荐(0)
摘要: 题目: 解答: 令0~n的数与nums中的数异或,运算中除了缺失值只出现一次外,其他数都出现两次等同于与自身异或。 1 class Solution { 2 public: 3 int missingNumber(vector<int>& nums) 4 { 5 int n = nums.size( 阅读全文
posted @ 2020-05-09 18:59 梦醒潇湘 阅读(116) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 class Solution { 2 public: 3 int search(vector<int>& nums, int target) 4 { 5 int left = left_bound(nums, target); 6 int right = right_bound( 阅读全文
posted @ 2020-05-09 18:56 梦醒潇湘 阅读(202) 评论(0) 推荐(0)
摘要: 题目: 解答: 方法一:双指针法 (1)创建两个指针 pA 和 pB,分别初始化为链表 A 和 B 的头结点。然后让它们向后逐结点遍历。 (2)当 pA到达链表的尾部时,将它重定位到链表 B 的头结点 (你没看错,就是链表 B); 类似的,当 pB 到达链表的尾部时,将它重定位到链表 A 的头结点。 阅读全文
posted @ 2020-05-09 18:53 梦醒潇湘 阅读(787) 评论(0) 推荐(0)
摘要: 题目: 解答: 方法一:优先级队列 1 class Solution { 2 public int nthUglyNumber(int n) { 3 PriorityQueue<Long> pq = new PriorityQueue<>(); 4 Set<Long> s = new HashSet 阅读全文
posted @ 2020-05-09 18:45 梦醒潇湘 阅读(179) 评论(0) 推荐(0)
摘要: 题目: 解答: 方法一:哈希,遍历。 1 class Solution { 2 public: 3 char firstUniqChar(string s) 4 { 5 if (s == "") 6 { 7 return ' '; 8 } 9 map<char, int> str; 10 11 fo 阅读全文
posted @ 2020-05-09 16:50 梦醒潇湘 阅读(146) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 class Solution { 2 public: 3 int maxSubArray(vector<int>& nums) 4 { 5 int sum = nums[0]; 6 int b = 0; 7 8 for (int i = 0; i < nums.size(); i 阅读全文
posted @ 2020-05-09 16:39 梦醒潇湘 阅读(100) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 ··· 38 下一页