Fingerprinting
#!/usr/bin/python
# -*- coding: utf-8 -*-
class A:
arr=[]
@classmethod
def push(cls,i):
cls.arr=[i]+cls.arr
@classmethod
def pop(cls):
ret=cls.arr[0]
cls.arr=cls.arr[1:]
return ret
A.arr=[66,661,662,663]
for i in range(10):
A.push(i)
import pprint
pprint.pprint(A.arr)
ret=A.pop()
pprint.pprint(A.arr)
小结:
1、
借助linkedlist,每次添加元素后,反转,取逆序
Implement Stack using Queues - LeetCode
https://leetcode.com/problems/implement-stack-using-queues/solution/
Implement Stack using Queues - LeetCode Articles
https://leetcode.com/articles/implement-stack-using-queues/
使用队列实现栈的下列操作:
- push(x) -- 元素 x 入栈
- pop() -- 移除栈顶元素
- top() -- 获取栈顶元素
- empty() -- 返回栈是否为空
注意:
- 你只能使用队列的基本操作-- 也就是
push to back,peek/pop from front,size, 和is empty这些操作是合法的。 - 你所使用的语言也许不支持队列。 你可以使用 list 或者 deque(双端队列)来模拟一个队列 , 只要是标准的队列操作即可。
- 你可以假设所有操作都是有效的(例如, 对一个空的栈不会调用 pop 或者 top 操作)。
Approach #1 (Two Queues, push - O(1), pop O(n))

Approach #2 (Two Queues, push - O(n), pop O(1) )

Approach #3 (One Queue, push - O(n), pop O(1))

package leetcode; import java.util.LinkedList;
import java.util.Queue; class MyStack { //one Queue solution
private Queue<Integer> q = new LinkedList<Integer>(); public static void main(String[] args) {
MyStack myStack = new MyStack();
myStack.push(-2);
myStack.push(0);
myStack.push(-3);
myStack.push(13);
myStack.pop();
myStack.top();
} // Push element x onto stack.
public void push(int x) {
q.add(x);
for (int i = 1; i < q.size(); i++) { //rotate the queue to make the tail be the head
q.add(q.poll());
}
} // Removes the element on top of the stack.
public int pop() {
return q.poll();
} // Get the top element.
public int top() {
return q.peek();
} // Return whether the stack is empty.
public boolean empty() {
return q.isEmpty();
}
}
class MyStack:
def __init__(self):
"""
Initialize your data structure here.
"""
self.myqueue=[]
def push(self, x: int) -> None:
"""
Push element x onto stack.
"""
self.myqueue=[x]+self.myqueue
def pop(self) -> int:
"""
Removes the element on top of the stack and returns that element.
"""
ret=self.myqueue[0]
self.myqueue=self.myqueue[1:]
return ret
def top(self) -> int:
"""
Get the top element.
"""
ret=self.myqueue[0]
return ret
def empty(self) -> bool:
"""
Returns whether the stack is empty.
"""
return len(self.myqueue)==0
# Your MyStack object will be instantiated and called as such:
# obj = MyStack()
# obj.push(x)
# param_2 = obj.pop()
Fingerprinting的更多相关文章
- 帆布指纹识别(canvas fingerprinting)
广告联盟或许网站运营者都希望能够精准定位并标识每一个个体,通过对用户行为的分析(浏览了哪些页面?搜索了哪些关键字?对什么感兴趣?点了哪些按钮?用了哪些功能?看了哪些商品?把哪些放入了购物车等等),为用 ...
- MaLoc: a practical magnetic fingerprinting approach to indoor localization using smartphones
https://www.indooratlas.com/ MaLoc: a practical magnetic fingerprinting approach to indoor localizat ...
- Magnetic Fingerprinting Approach to Indoor Localization
Magnetic Fingerprinting Approach to Indoor Localization
- DNA fingerprinting|haplotpe|frequency of polymorphism|限制性标记的多态性
5.4利用RFLP和SNP绘制遗传图 因为限制性标记可以确定那个分子水平上的突变(即已知基因座),但是无法和蛋白质功能相联系.所以我们采用限制性标记的多态性,即该限制酶识别的位点若发生突变,则大概率在 ...
- HTML5 + JS 网站追踪技术:帆布指纹识别 Canvas FingerPrinting Universally Unique Identifier,简称UUID
1 1 1 HTML5 + JS 网站追踪技术:帆布指纹识别 Canvas FingerPrinting 1 一般情况下,网站或者广告联盟都会非常想要一种技术方式可以在网络上精确定位到每一个个体,这 ...
- HTML5 & canvas fingerprinting
HTML5 & canvas fingerprinting demo https://codepen.io/xgqfrms/full/BaoMWMp window.addEventListen ...
- 《Shazam It! Music Recognition Algorithms, Fingerprinting, and Processing》译文
最近看到一篇老外写的博客,简单介绍了shazam的工作原理.图非常好,所以就把它翻译成中文,希望对搞听歌识曲的人有帮助. 你可能遇到这样的场景:在酒吧或者餐厅听到你非常熟悉的歌,也许你曾经听过无数次, ...
- Gathering Fingerprinting
1. Banner grabbing with Netcat Netcat is multipurpose networking tool that can be used to perform mu ...
- 设备指纹(Device Fingerprinting)是什么?
简单来讲,设备指纹是指可以用于标识出该设备的设备特征或者独特的设备标识.设备指纹因子通常包括计算机的操作系统类型,安装的各种插件,浏览器的语言设置及其时区 .设备的硬件ID,手机的IMEI,电脑的网卡 ...
随机推荐
- loj 1018(状压dp+记忆化搜索)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25844 思路:首先预处理出点在同一直线上的所有的点集状态(dp[i ...
- BZOJ4361 : isn
设$f[i]$表示长度为$i$的不下降子序列的个数. 考虑容斥,对于长度为$i$的子序列,如果操作不合法,那么之前一定是一个长度为$i+1$的子序列,所以答案$=\sum_{i=1}^n(f[i]\t ...
- BZOJ3749 : [POI2015]Łasuchy
设f[i][S]表示第i份食物被两个人吃的状态为S是否有可能,枚举f[1][]的情况后检验 f[i][0]=(f[i-1][1]&a[i-1]>=a[i])|(f[i-1][3]& ...
- CentOS6.4 安装Nagios 并监控端口
1.下载所需文件nagios-3.4.3.tar.gz,nagios-plugins-1.4.15.tar.gz,nrpe-2.14.tar.gz,sendEmail-v1.56.tar.gz 下载地 ...
- c++ for_each()与仿函数
for_each有一个独门绝技,其他算法没有,那就是可以返回值来获取函数的状态 #include <iostream> #include <vector> #include & ...
- BJOI2015 Day3
(wzj这蒟蒻终于滚Cu了,今天第一题SB题写+调用了1.5h,测试时还WA了一个点.第二题数位DP20分钟写完遇到鬼打墙,中间一切正常最后输出一坨负数.调了1h发现是一个数组开小了.又花了20+mi ...
- div里嵌套了img底部会有白块问题和图片一像素问题解决
div里嵌套了img底部会有白块 因为img默认是按基线(baseline)对齐的.对比一下图片和右边的p, q, y等字母,你会发现这三个字母的“小尾巴”和图片下方的空白一样高.下面这张图中的黑线就 ...
- 使用Python中的urlparse、urllib抓取和解析网页(一)(转)
对搜索引擎.文件索引.文档转换.数据检索.站点备份或迁移等应用程序来说,经常用到对网页(即HTML文件)的解析处理.事实上,通过Python 语言提供的各种模块,我们无需借助Web服务器或者Web浏览 ...
- Linux下java获取CPU、内存、磁盘IO、网络带宽使用率
一.CPU 使用proc文件系统,"proc文件系统是一个伪文件系统,它只存在内存当中,而不占用外存空间.它以文件系统的方式为访问系统内核数据的操作提供接口.用户和应用程序可以通过proc得 ...
- 使用Expression做Linq的參數化排序
Linq非常的好用,減少大量的資料庫操作手序,使用具名的類別,減少了在程式中寫SQL寫錯字的可能性,問題來了,如果我想用QueryString中的參數,作為排序的依據,但是因為是具名的類別,不能指定字 ...