- 博客(25)
- 资源 (1)
- 收藏
- 关注
原创 218. The Skyline Problem [leetcode]
这道题的原理就是,寻找有效的拐点。该点满足不被其他任何building覆盖,或者为一个building右部的拐点。一个building具有的覆盖力从左边起持续到右边结束。当右边结束的时候,该building对有部分的所有building都拾取了覆盖力。因此,我们先将所有的building的左边线段和右边线段分开,将位置和高度信息以pair的形式存入vector中。再将所有线段按照位置的先后排序。然后遍历这些线段。当遍历到开始(building的左边线段)线段时,将其加入multiset容器m中,当遍历
2017-08-11 16:39:59
297
原创 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
224
原创 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
215
原创 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
198
原创 260. Single Number III [leetcode]
每次遇得这种位操作的新题,都不会做。很无奈。看了大神的讲解才恍然大悟。哎。原理就是对数组进行分组,使得两个单独的数a、b被分到不同的组。再在不同的组里面通过异或的操作分别得出两个数。怎么样分组呢? 寻找a与b的不同点。此时,不用考虑其他数,因为其他数都是成双的,相同的数一定会被分到同一组。通过异或操作我们可以得到a与b不同的位。我们选取a^b的最低不为0的位。通过判断每个数
2017-08-10 00:33:18
215
原创 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
198
原创 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
254
原创 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
282
原创 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
251
原创 189. Rotate Array [Leetcode]
题目:--------------------------------------------------------------------------------------------------------------------------------------Rotate an array of n elements to the right by k steps
2017-08-07 17:23:07
287
原创 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
339
原创 420. Strong Password Checker [leetcode]
思路: 有三个问题需要解决: 1、缺失字符种类问题(大写,小写、数字) 可用操作:replace,insert 2、长度问题 可用该操作:insert(< 6),delete(> 20) 3、重复问题 可用操作: replace,insert,delete,其中replace的解决方法最优。可以看到各种问题之间是有重复性的,也就是说可以通过解决某个问题,同时解决另一个问题。
2017-08-06 11:59:59
846
原创 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
210
原创 150. Evaluate Reverse Polish Notation [Leetcode]
用stack来保存还未操作的数字。 一旦遇见操作符,则pop出stack中的头两个数字,进行计算,再把结果push进stack中。class Solution {public: int evalRPN(vector<string>& tokens) { stack<int> nums; for (auto i : tokens) {
2017-07-31 15:36:26
197
原创 384. Shuffle an Array [Leetcode]
利用swap+随机数生成一个随机的序列。class Solution {public: Solution(vector<int> nums) { srand(time(NULL)); this->originalNums = nums; size = nums.size(); } /** Resets the array to
2017-07-31 14:55:45
233
原创 153. Find Minimum in Rotated Sorted Array [Leetcode]
用二分查找法来解决:class Solution {public: int findMin(vector<int>& nums) { int left = 0, right = nums.size() - 1; while (right > left) { int mid = left + (right - left) / 2;
2017-07-31 14:24:14
197
原创 49. Group Anagrams [Leetcode]
核心思想: 利用mashmap来存储同构词对应的字符表。其中每一个key对应着结果vector中字符集所在的index。运行耗时:26msclass Solution {public: vector<vector<string>> groupAnagrams(vector<string>& strs) { vector<vector<string>> words;
2017-07-31 11:35:02
184
转载 静态链接库LIB和动态链接库DLL
静态链接库LIB和动态链接库DLL静态链接库与动态链接库都是共享代码的方式,如果采用静态链接库,则无论你愿不愿意,lib 中的指令都全部被直接包含在最终生成的 EXE 文件中了。但是若使用 DLL,该 DLL 不必被包含在最终 EXE 文件中,EXE 文件执行时可以“动态”地引用和卸载这个与 EXE 独立的 DLL 文件。静态链接库和动态链接库的另外一个区别在于静态链接库中不能再包含其他的动态链接库
2016-09-05 14:11:08
309
转载 makefile中伪目标详解
伪目标 下面的“clean”目标,是一个“伪目标”, clean: rm *.o temp 我们生成了许多文件编译文件,我们也应该提供一个清除它们的“目标”以备完整地重编译而用。 (以“make clean”来使用该目标) ,调用相应的规则,来清除许多编译的文件(如:*.o文件)因为,我们并不生成“clean”这个文件。“伪目标”并不
2016-09-05 12:19:07
5470
2
原创 leetcode two sum
先用快排,时间复杂度为nlogn,再在每个循环里用二分进行查找,时间复杂度为nlogn,总体时间复杂度为nlognclass Solution {public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> result, copy_nums = nums; sort(nums
2016-05-29 14:07:44
235
原创 photo mosaic 拼图马赛克
原理: 读取原始图片,进行分割,分析每个小块RGB均值,并存储。 读取若干图片,提取并存储各个图片的RGB均值。与原始图片的每个小块进行匹配。 可以采用OpenMP进行并行加速#include "mainwindow.h"#include "ui_mainwindow.h"#include <QTextStream>#include <QBoxLayout>MainWindow::Mai
2016-05-12 22:32:39
1808
1
原创 汇编实验 固定时间改变背景色及字符位置
题目:在屏幕上显示一个“*”字符。要求背景颜色不断改变(间隔0.5 秒),且“*”字符可在屏幕上无规则移动(速度0.1 秒)。用中断来控制时间间隔。写的心好累。。。。然而这个随机数的生成好像根据个人电脑的情况不同,我的电脑好像挺有规律的。。。RAND MACRO N ;通过中断,获取返回在N内的随机数 MOV AH,0 INT 1AH M
2016-05-12 22:25:56
1661
原创 斐波那契数 32位windows 汇编
输入N,输出第N个斐波那契数.386.model flat,stdcalloption casemap:noneincludelib msvcrt.libprintf PROTO C :dword,:VARARGscanf PROTO C :dword,:VARARG.dataN dd0pre1 dd1pre2 dd1
2016-05-12 22:17:52
495
转载 Opengl 单双缓冲区区别
转自http://blog.youkuaiyun.com/mfcappwizard/article/details/6965617单缓冲,实际上就是将所有的绘图指令在窗口上执行,就是直接在窗口上绘图,这样的绘图效率是比较慢的,如果使用单缓冲,而电脑比较慢,你回到屏幕的闪烁。双缓冲,实际上的绘图指令是在一个缓冲区完成,这里的绘图非常的快,在绘图指令完成之后,再通过交换指令把完成的图形立即显示在屏幕上,这就
2016-03-20 10:43:35
3323
2017美国秋季研究生申请院校详情
2016-09-28
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人