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,电脑的网卡 ...
随机推荐
- js event 事件兼容浏览器 ie不需要 event参数 firefox 需要
js event 事件兼容浏览器 ie不需要 event参数 firefox 需要 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...
- adb shell 命令详解(转)
adb介绍 SDK的Tools文件夹下包含着Android模拟器操作的重要命令adb,adb的全称为(Android Debug Bridge就是调试桥的作用.通过adb我们可以在Eclipse中方面 ...
- C语言位运算详解(转载)
转载自:http://www.cnblogs.com/911/archive/2008/05/20/1203477.html 位运算是指按二进制进行的运算.在系统软件中,常常需要处理二进制位的问题.C ...
- web_save_timestamp_param获取时间戳函数介绍
函数说明: web_save_timestamp_param("tStamp", LAST); lr_output_message("%s",lr_eval_s ...
- Linux常用命令_(文件搜索)
文件查找主要包含以下几个命令 which.whereis.grep.find.wc
- Linux磁盘分区与格式化
磁盘分区格式说明 linux分区不同于windows linux下分区标示: 例如:hda1 hd这两个字母表示分区所在的设备类型,hd标示IDE类型硬盘,sd表示SCSI类型硬盘 第三字母a标示硬盘 ...
- Burp Suite详细使用教程
Burp Suite详细使用教程-Intruder模块详解 最近迷上了burp suite 这个安全工具,百度了关于这个工具的教程还卖900rmb...ohno.本来准备买滴,但是大牛太高傲了,所以没 ...
- 2^x mod n = 1
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- datetime与smalldatetime之间的区别
1.一直以为smalldatetime和datetime的差别只是在于时间范围: smalldatetime的有效时间范围1900/1/1~2079/6/6datetime的有效时间范围1753/1/ ...
- WPF 碰撞检测
have tested this, it worked, at least for me var x1 = Canvas.GetLeft(e1); var y1 = Canvas.GetTop(e1) ...