Write a function:class Solution { public int solution(int[] A); }that, given an array A consisting of N integers, returns the number of pairs (P, Q) s...
分类:
其他好文 时间:
2015-01-04 06:22:50
阅读次数:
277
https://oj.leetcode.com/problems/swap-nodes-in-pairs/http://fisherlei.blogspot.com/2013/01/leetcode-swap-nodes-in-pairs.html/**
*Definitionforsingly-linkedlist.
*publicclassListNode{
*intval;
*ListNodenext;
*ListNode(intx){
*val=x;
*next=null;
*}
*}
*/
publ..
分类:
其他好文 时间:
2015-01-02 16:12:21
阅读次数:
151
题目大意
有n个数,m个查询,对于每个查询,询问指定区间,有多少个数对的绝对值小于等于2。
解题思路
莫队O^1.5
首先将询问离线处理左端点进行编号,每sqrt(n)个为一组
sort结构体 当左端点编号相同时,比较右端点大小。小的放在前面。
对于每组询问暴力处理,只需处理当前新加入(删除的数字在当前区间内有多少点和它的绝对值只差小于2即可)
唯一要注意的是加点是...
分类:
编程语言 时间:
2014-12-31 20:15:07
阅读次数:
283
题目:Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list a...
分类:
编程语言 时间:
2014-12-26 14:27:01
阅读次数:
205
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
"((()))", "(()())", "(())()", "()(())", "()()()"
...
分类:
其他好文 时间:
2014-12-25 20:40:36
阅读次数:
143
设计一个简单的事件派发器,个人觉得最重要的一点就是如何保证事件派发过程中,添加或删除同类事件,不影响事件迭代顺序和结果,只要解决这一点,其它都好办。为了使用pairs遍历函数,重写了pairs(lua 5.2以上版本不需要):stdext.lualocal _ipairs = ipairsfunct...
分类:
其他好文 时间:
2014-12-22 14:09:37
阅读次数:
268
Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2-...
分类:
其他好文 时间:
2014-12-19 17:05:17
阅读次数:
192
环境全局变量table lua把所有的全局变量存在一个table里,并把这个table赋值给一个全局变量_G _G也在这个全局变量的table里,它就是一个普通的全局变量 可以用这种方法遍历所有全局变量 for k, v in pairs(_G) do print(k,v) end 可以使用...
分类:
其他好文 时间:
2014-12-17 15:55:54
阅读次数:
208
Description
You are given two positive integers A and B in Base C. For the equation:
A=k*B+d
We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now...
分类:
其他好文 时间:
2014-12-16 21:05:09
阅读次数:
244
One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are out of order with respect to each other. For instance, in the...
分类:
其他好文 时间:
2014-12-16 20:51:37
阅读次数:
272