每周完成一个ARTS(Algorithm,Review,Tips,Share):7号小组成员-追风筝的人,每周至少做一道leetcode算法题,阅读并点评至少一篇英文技术文章,学习至少一个技术技巧,分享一篇有观点和思考的技术文章.
Algorithm
使用栈实现队列的下列操作:push(x)--将一个元素放入队列的尾部。pop()--从队列首部移除元素。peek()--返回队列首部的元素。empty()--返回队列是否为空。示例:MyQueuequeue=newMyQueue();queue.push(1);queue.push(2);queue.peek();//返回1queue.pop();//返回1queue.empty();//返回falseclassMyQueue{publicStackIntegers1;publicStackIntegers2;/**Initializeyourdatastructurehere.*/publicMyQueue(){s1=newStackInteger();s2=newStackInteger();}/**Pushelementxtothebackofqueue.*/publicvoidpush(intx){s1.push(x);}/**Removestheelementfrominfrontofqueueandreturnsthatelement.*/publicintpop(){if(s1.empty()s2.empty()){thrownewRuntimeException("queueisempty");}elseif(s2.empty()){while(!s1.empty()){s2.push(s1.pop());}}returns2.pop();}/**Getthefrontelement.*/publicintpeek(){if(s2.empty()s1.empty()){thrownewRuntimeException("queueisempty");}elseif(s2.empty()){while(!s1.empty()){s2.push(s1.pop());}}returns2.peek();}/**Returnswhetherthequeueisempty.*/publicbooleanempty(){returns1.empty()s2.empty();}}/***YourMyQueueobjectwillbeinstantiatedandcalledassuch:*MyQueueobj=newMyQueue();*obj.push(x);*intparam_2=obj.pop();*intparam_3=obj.peek();*booleanparam_4=obj.empty();*/
review
BM算法的时间复杂度分析:字符串匹配有PK,KMP,BM算法
转载请注明:http://www.quwenlai.com/zexs/17669.html