自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(13)
  • 资源 (1)
  • 收藏
  • 关注

原创 218. The Skyline Problem [leetcode]

这道题的原理就是,寻找有效的拐点。该点满足不被其他任何building覆盖,或者为一个building右部的拐点。一个building具有的覆盖力从左边起持续到右边结束。当右边结束的时候,该building对有部分的所有building都拾取了覆盖力。因此,我们先将所有的building的左边线段和右边线段分开,将位置和高度信息以pair的形式存入vector中。再将所有线段按照位置的先后排序。然后遍历这些线段。当遍历到开始(building的左边线段)线段时,将其加入multiset容器m中,当遍历

2017-08-11 16:39:59 271

原创 187. Repeated DNA Sequences [leetcode]

题目:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DN

2017-08-11 15:18:34 201

原创 347. Top K Frequent Elements [leetcode]

法 一:hashmap + vector时间:O(n)class Solution {public: vector topKFrequent(vector& nums, int k) { vector res; if (k < 1) return res; if (k >= nums.size()) return nums;

2017-08-11 11:35:33 194

原创 220. Contains Duplicate III [leetcode]

题目:Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute

2017-08-10 15:57:09 185

原创 260. Single Number III [leetcode]

每次遇得这种位操作的新题,都不会做。很无奈。看了大神的讲解才恍然大悟。哎。原理就是对数组进行分组,使得两个单独的数a、b被分到不同的组。再在不同的组里面通过异或的操作分别得出两个数。怎么样分组呢? 寻找a与b的不同点。此时,不用考虑其他数,因为其他数都是成双的,相同的数一定会被分到同一组。通过异或操作我们可以得到a与b不同的位。我们选取a^b的最低不为0的位。通过判断每个数

2017-08-10 00:33:18 197

原创 110. Balanced Binary Tree [leetcode]

用递归来解题。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * };

2017-08-09 20:26:59 178

原创 164. Maximum Gap [leetcode]

这道题可以有两种刚解法:解法一:基于bucket sort的方法:有n个未排序的数字。1、先求出数组内最大数max和最小数min。2、求出每个桶内的数字范围:gap = (max - min) / (n - 1)。3、算出桶的数量: N = (max - min)/ gap + 1  (可知 N >= n)每个桶对应的数字范围为: 第一个:[min, min

2017-08-09 19:54:17 234

原创 89. Gray Code [leetcode]

89. Gray CodeThe gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, pri

2017-08-08 12:15:11 261

原创 142. Linked List Cycle II [leecode]

利用 floyd cycle detection原理来解题分析详见 博客287. Find the Duplicate Number [Leetcode]代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * L

2017-08-08 10:50:09 223

原创 189. Rotate Array [Leetcode]

题目:--------------------------------------------------------------------------------------------------------------------------------------Rotate an array of n elements to the right by k steps

2017-08-07 17:23:07 262

原创 287. Find the Duplicate Number [Leetcode]

这题首先想到的最简单的方法是用快排然后再遍历。然而题目要求不能改变原来的数组顺序。所以快排的方法被排除。后来想到了用binary search来做。方法一:Binary Search由于数字的范围是确定的[1,n]取数字mid,如果【1,mid)没有重复的数字的话,这区间的数字个数应该 mid - 1, 如果在(mid,n] 之间没有重复数字的话,该区间的数字个数应该 (m

2017-08-07 14:58:53 313

原创 420. Strong Password Checker [leetcode]

思路: 有三个问题需要解决: 1、缺失字符种类问题(大写,小写、数字) 可用操作:replace,insert 2、长度问题 可用该操作:insert(< 6),delete(> 20) 3、重复问题 可用操作: replace,insert,delete,其中replace的解决方法最优。可以看到各种问题之间是有重复性的,也就是说可以通过解决某个问题,同时解决另一个问题。

2017-08-06 11:59:59 815

原创 Battleships in a Board [Leetcode]

从上到下,从左到右遍历,遇到X,判断左边和上边是否有X,没的话则为新出现的battleship。class Solution {public: int countBattleships(vector<vector<char>>& board) { int res = 0; for (int i = 0; i < board.size(); i++) {

2017-08-01 18:17:27 183

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除