用两个栈实现队列的功能
用两个栈实现队列的功能思路如下:(1)将设有两个空栈A,B;A负责入队,B负责出队。(2)入队时,将元素压入栈A(3)出队时,若B栈为空,将A中的元素全部出栈,并压入B中,然后B的栈顶元素出栈。若B栈不为空,直接将B的栈顶元素出栈。
[LeetCode] Contains Duplicate II
Contains Duplicate II Given an array of integers and an integer k, return true if and only if there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference be...
心愿
[LeetCode] Reorder List
Reorder ListGiven a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {...
[LeetCode] Binary Tree Preorder Traversal (非递归的先序遍历)
Binary Tree Preorder TraversalGiven a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 ...
北京东路的日子
[LeetCode] Insertion Sort List
Insertion Sort ListSort a linked list using insertion sort.解题思路:类似于插入排序法。与数组的插入排序法不同的是,链表的插入排序扫描顺序是从左往右扫描,找到第一个大于指定元素的节点N,然后将之插在N节点前面。今天状态非常不好,这个题目都NG了好几遍。。。/** * Definition for ...
[LeetCode] Jump Game
Jump GameGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine ...
[LeetCode] Maximum Subarray
Maximum SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarra...
[LeetCode] Pow(x, n)
Pow(x, n) Implement pow(x, n).解题思路:这里n是整数,注意可能是负数,因此需要先将其转化成正数。若直接用循环的方法做,会产生超时错误。我们可以这么做。比如求2^6,我们需要求2^(2*3)=4^3=4*4^2,这样时间复杂度为O(logn)。注意几个特殊的情况,当n==1时,返回x本身,当n==0时,返回1,当n为偶数时,返回myPow(x*x, ...
[LeetCode] Anagrams
AnagramsGiven an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.解题思路:anagrams(变位字)是指对于两个单词来说,长度相同,且构成的字符除了顺序可以不同外,个数都相同。如cinema和iceman就是变位字。判断两...
[LeetCode] Subsets
SubsetsGiven a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exampl...
[LeetCode] Kth Largest Element in an Array
Kth Largest Element in an ArrayFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given ...
[LeetCode] Combination Sum III
Combination Sum IIIFind all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of ...
[LeetCode] Contains Duplicate
Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false i...
[LeetCode] Rotate Image
Rotate ImageYou are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?解题思路:题目要求原地算法。假设坐标轴如上所示。顺时针旋转90度,...
[LeetCode] House Robber II
House Robber IINote: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much...
程序远表白网,对Ta Say Love
历经两周构思与取材,两天编写代码,程序远表白网V1.0版已经上线啦。网址:http://www.kangry.net/love/。整合了当前网站其他人做的一些模板,修改了一些Bug。目前尚不支持手机版的(手机版样式可能不对)建议用Chorme、Firefox、IE9+等高级浏览器打开。祝你表白成功!插入自定义音乐教程:http://www.kangry.net/blog/?type=article...
如何在程序远表白网中插入自定义音乐?
发现很多人想在程序远表白网(http://www.kangry.net/love/)中自定义背景音乐,但是由于网站空间的限制,我上传的可选音乐非常有限。如果你想自定义背景音乐,可以按照下列教程来做。注:很多朋友贴了虾米、百度、酷我音乐页面的链接,其实是不对滴,要贴出mp3类型的网址路径。下面介绍如何在http://musicase.me/中找到你要的背景音乐链接。这个网址是供海外用户听国内音乐的,...
JS获得当前时间,并格式化
function getNowFormatDate() { var date = new Date(); var year = date.getFullYear(); var month&n...