我正在尝试使用堆来解决问题"合并K列表",它合并了k个已排序的链表并将其作为一个排序列表返回.通常我创建一个min heap来存储所有列表节点,并使用预定义函数LessThanLinkedList()进行比较.但我发现第62行和第75行中的pop_heap()操作永远不会起作用.虽然我使用预定义的比较函数作为参数,但它不会删除堆的顶部.以下是我的代码.我使用visual studio 2010作为IDE.谁知道原因?非常感谢你的帮助!
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};
using namespace std;
class Solution {
public:
static bool LessThanLinkedList( const ListNode * l1, const ListNode * l2)
{
return( l1->val > l2->val );
}
ListNode *mergeKLists(vector<ListNode *> &lists) {
int idx;
bool ball_list_null;
ListNode * pNode;
ListNode *new_head;
ball_list_null = true;
for( idx = 0; idx < lists.size(); idx++ …Run Code Online (Sandbox Code Playgroud) 我试图使用以下JavaScript RE来匹配字符串,其中允许的字符是大写或小写字母,数字,超量( - )和句点(.).不允许使用下划线"_":
pattern = /^([a-zA-z0-9\-\.]+)$/
Run Code Online (Sandbox Code Playgroud)
但是当我在Chrome控制台中运行测试时:pattern.test("_ linux");
结果是真的,但根据我们的规则应该是假的.什么原因?