- 博客(49)
- 收藏
- 关注
转载 进程基础
1.什么是进程?进程是操作系统提供的抽象之一。有了进程的概念之后,CPU才有了并发或者伪并发的可能性。通俗的说来,当你的写的程序运行起来后,那么它就是一个进程了。2.进程,伪并发,并发首先说说并发,并发指的是在某一个时刻某些事件同时发生。假设你的电脑只有一个CPU(这里一个指单核),然而你却有很多程序要同时运行,即你的电脑上将有很多进程存在,那么CPU就将提供一种伪...
2019-05-05 19:58:00
112
转载 设计模式--桥模式
考虑要设计一个Messager模块,这个模块要实现如下功能登录发送消息播放声音(登录或者播放的时候播放声音)画图(登录的时候显示的图片)那么最直观的设计如下class Messager {public: virtual void Login(string userName, string password) = 0; virtual v...
2019-05-04 00:06:00
125
转载 设计模式--装饰者模式
考虑程序要对一类流(网络流,IO流等等)进行操作。进行什么操作呢?可能在读(Read)这个流的时候对这个流进行加密,也可能对这个流进行缓存。 那么很自然的能设计出以下这些类class Stream {public: void Read();};class IOStream : public Stream {}; ...
2019-05-01 13:31:00
125
转载 设计模式---模板方法模式
曾经第一次学习设计模式的时候,总觉得这玩意没有用。这段时间重新看视频学习,才领略到设计模式的好处。今天我想说说模板方法模式。 模板想必大家在生活中是经常用的。比如说写简历可以套一个简历模板,写一个网页可以套一个前端模板。当你使用一个模板的时候,你会根据自己的需求去修改模板的一部分内容。对于模板方法的使用和设计,与现实中的模板是基本一致的。这也是为什么它叫这个名字。 接下来...
2019-04-29 13:05:00
105
转载 说说new 和 malloc()
熟悉c++的朋友应该都知道,c++提供给了程序员与硬件打交道的可能性,比如说内存管理。一个高水平的c++程序员可以将c++程序的性能优化到极致,榨干硬件资源。而现在我想说说与内存管理有关的new 和 malloc()。 先说说malloc(),malloc是从C语言那里继承过来的一个函数,其用于分配一片内存,它的返回结果是一个指向你所需求的内存的指针,其函数原型和使用例子如下:...
2019-04-27 11:51:00
159
转载 [Leetcode]650. 2 Keys Keyboard
Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:Copy All: You can copy all the characters present on the notepad (pa...
2018-01-26 13:01:00
96
转载 [Leetcode]376. Wiggle Subsequence
A sequence of numbers is called awiggle sequenceif the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be eithe...
2018-01-24 15:51:00
162
转载 [Leetcode]198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent ...
2018-01-23 20:49:00
100
转载 [Leetcode]121. Best Time to Buy and Sell Stock
Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stoc...
2017-12-24 08:33:00
105
转载 [Leetcode]238. Product of Array Except Self
Given an array ofnintegers wheren> 1,nums, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i].Solve itwithout divisionand in...
2017-11-28 17:48:00
74
转载 [Leetcode]442. Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤n(n= size of array), some elements appeartwiceand others appearonce.Find all the elements that appeartwicein this array.Could you do it without e...
2017-11-28 16:26:00
86
转载 [Leetcode]643. Maximum Average Subarray I
Given an array consisting ofnintegers, find the contiguous subarray of given lengthkthat has the maximum average value. And you need to output the maximum average value.Example 1:Input: [...
2017-11-21 17:37:00
105
转载 [Leetcode]724. Find Pivot Index
Given an array of integersnums, write a method that returns the "pivot" index of this array.We define the pivot index as the index where the sum of the numbers to the left of the index is equa...
2017-11-20 22:26:00
90
转载 [Leetcode]86. Partition List
Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each...
2017-11-08 18:50:00
108
转载 [Leetcode]109. Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a heightbalanced BST.思路:二分法;/** * Definition for singly-linked list. * public class ListNode {...
2017-11-05 14:05:00
86
转载 [Leetcode]617. Merge Two Binary Trees
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary...
2017-11-05 09:43:00
101
转载 [Leetcode]450. Delete Node in a BST
Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.Basically, the deletion can be divide...
2017-11-05 09:29:00
108
转载 [Leetcode]101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree[1,2,2,3,4,4,3]is symmetric: 1 / \ 2 2 / \ / \3 4...
2017-11-04 15:22:00
95
转载 [Leetcode]160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘ ...
2017-11-03 15:41:00
67
转载 [Leetcode]142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Note:Do not modify the linked list.思路:我的想法是先用快慢指针判断是否有环,如果有环的话,找出快慢指针相遇的那个点。然后让一个指针一直在那个环里...
2017-11-03 15:07:00
60
转载 [Leetcode]147. Insertion Sort List
Sort a linked list using insertion sort.链表的插入排序思路,递归到链表尾,然后循环插入; 1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNo...
2017-11-03 06:42:00
92
转载 [Leetcode]83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3....
2017-11-02 13:50:00
59
转载 [Leetcode]203. Remove Linked List Elements
Remove all elements from a linked list of integers that have valueval.ExampleGiven:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val= 6Return:1 --> 2 --> 3 --> 4 --> ...
2017-11-01 21:44:00
64
转载 [Leetcode]141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?思路:快慢指针,设置一个走两步的快指针,和一个走一步的慢指针,如果有环,则它们一定会相遇。 1 /** 2 * Definition for...
2017-11-01 12:50:00
76
转载 [Leetcode]108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:既然数组里的元素已经按升序排好序了,那么不难想到用二分法来做这道题。/** * Definition for a binary tree node...
2017-10-29 13:25:00
106
转载 [Leetcode]695. Max Area of Island
Given a non-empty 2D arraygridof 0's and 1's, anislandis a group of1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are s...
2017-10-29 11:25:00
63
转载 [Leetcode]674. Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longestcontinuousincreasing subsequence.Example 1:Input: [1,3,5,4,7]Output: 3Explanation: The longest continuous increasing subse...
2017-10-27 16:04:00
67
转载 [Leetcode]485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecu...
2017-10-27 13:09:00
58
转载 [Leetcode]66. Plus One
Given a non-negative integer represented as anon-emptyarray of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself....
2017-10-27 09:56:00
59
转载 [Leetcode]628. Maximum Product of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24...
2017-10-26 22:55:00
55
转载 [Leetcode]414. Third Maximum Number
Given anon-emptyarray of integers, return thethirdmaximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).Example 1:Input: [3, 2...
2017-10-26 16:35:00
57
转载 [Leetcode]283. Move Zeroes
Given an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.For example, givennums = [0, 1, 0, 3, 12], after calling yo...
2017-10-26 13:23:00
58
转载 [Leetcode]35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the arr...
2017-10-26 12:46:00
62
转载 [Leetcode]561. Array Partition I
Given an array of2nintegers, your task is to group these integers intonpairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as...
2017-10-26 07:52:00
57
转载 [Leetcode]27. Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory....
2017-10-25 22:34:00
56
转载 [Leetcode]88. Merge Sorted Array
Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is greater or equal tom+n) to hold addi...
2017-10-25 22:09:00
57
转载 [Leetcode]26. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this in place w...
2017-10-24 21:06:00
80
转载 [Leetcode]268. Missing Number
Given an array containingndistinct numbers taken from0, 1, 2, ..., n, find the one that is missing from the array.For example,Givennums=[0, 1, 3]return2.Note:Your algorithm should run...
2017-10-24 20:08:00
52
转载 [Leetcode]532. K-diff Pairs in an Array
Given an array of integers and an integerk, you need to find the number ofuniquek-diff pairs in the array. Here ak-diffpair is defined as an integer pair (i, j), whereiandjare both numbe...
2017-10-24 12:50:00
81
转载 [Leetcode]110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofeverynode never di...
2017-10-23 13:38:00
74
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人