小编Abh*_*gde的帖子

如何在Java中匹配字符串(?,?,?)

我的输入字符串的形式为:字符串输入=“(?,?,?)”;

我无法提出有效的正则表达式来识别此类字符串

我已经尝试过以下正则表达式:

String regex = "(\\?,*)"; 
Run Code Online (Sandbox Code Playgroud)

上面的正则表达式对诸如(?,?)或(?,?,?,?)等输入字符串的声明失败

java regex

4
推荐指数
1
解决办法
100
查看次数

实现循环队列的微妙错误

我正在尝试实现如下的简单循环队列操作

void push(int theElement)
{
  //Check if the push causes queue to overflow
    if  (((queueBack + 1 ) % arrayLength) == queueFront) {
       std::cout<<"Queue is full."<<std::endl;
       return ;
    } 
    queueBack = (queueBack + 1) % arrayLength;
    inputArray[queueBack] = theElement;
}

int pop()
{
   //Check if queue  is already empty
  if ( queueFront == queueBack ) {
    std::cout<<"Queue is empty."<<std::endl;
    return;
  }
  queueFront = (queueFront + 1 ) % arrayLength;
  return inputArray[queueFront];

}
Run Code Online (Sandbox Code Playgroud)

考虑到最初的queueFront = 0和queueBack = 0,上面的代码会产生一个完整的队列,即使实际上并非如此.我该如何改正?在第一种情况下我的实现是否正确?

测试用例最初为arrayLength = 3,queueFront …

c queue

3
推荐指数
1
解决办法
185
查看次数

采访 - 在数组中查找偶数和对

给定一个数组,你如何返回总和为偶数的对数?

例如:

a[] = { 2 , -6 , 1, 3, 5 }
Run Code Online (Sandbox Code Playgroud)

在这个数组中,与偶数和成对的nos是(2,-6),(1,3),(1,5),(3,5)

函数应返回4,因为有4对或-1,如果没有.

预期时间复杂度 - O(N)最坏情况预期空间复杂度 - O(N)最坏情况

方法1:蛮力

Start with the first number
  Start with second number
      assign the sum to a temp variable
      check if the temp is even
          If it is increment evenPair count
      else
          increment the second index
Run Code Online (Sandbox Code Playgroud)

这里的时间复杂度是O(N2)

c c++ arrays

1
推荐指数
1
解决办法
1753
查看次数

标签 统计

c ×2

arrays ×1

c++ ×1

java ×1

queue ×1

regex ×1