我正在参加算法的在线课程,并尝试实现一个在数字列表中查找反转次数的mergesort实现.但是,由于返回的反转次数明显低于我在执行暴力攻击时所获得的数量,因此无法确定我的实施方式是错误的.我已经将我的mergesort方法的实现放在下面
/**
*
*/
package com.JavaReference;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class ReadFile {
public static void main(String args[]){
int count=0;
Integer n[];
int i=0;
try{
n=OpenFile();
int num[] = new int[n.length];
for (i=0;i<n.length;i++){
num[i]=n[i].intValue();
// System.out.println( "Num"+num[i]);
}
count=countInversions(num);
}
catch(IOException e){
e.printStackTrace();
}
System.out.println(" The number of inversions"+count);
}
public static Integer[] OpenFile()throws IOException{
FileReader fr=new FileReader("C:/IntegerArray.txt");// to put in file name.
BufferedReader textR= new BufferedReader(fr);
int nLines=readLines();
System.out.println("Number of lines"+nLines);
Integer[] nData=new Integer[nLines];
for (int …Run Code Online (Sandbox Code Playgroud) 我正试图找到解决问题的方法
Find two elements in balanced BST which sums to a given a value.
Run Code Online (Sandbox Code Playgroud)
约束时间O(n)和空间O(logn).
我想知道以下算法是否有效.
int[] findSum(Node root, int sum){
int[] sumArray;
for (int i=0;i<sum;i++) {
if (root.contains(i) && root.contains(sum-i)) {
sumArray[0] = i;
sumArray[1] = sum-i;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我明白我的方法可能是错的.我很感激我的伪代码/更好的算法的任何反馈/更正
我正在尝试安装moodle,但在指定moodle 数据文件夹的路径时遇到错误。基本上,他们希望它位于无法从网络访问的地方。
我试过把它放在/var/moodledata里面给我一个错误说
Parent directory (/var) is not writeable. Data directory (/var/moodledata) cannot be created by the installer.
,在/var/www/moodledata哪给我一个错误说Dataroot location is not secure
我尝试将 sudo(permissions) 赋予/var/www/文件夹,并尝试install.php通过注释掉以下几行来跳过验证
/*while(is_dataroot_insecure()) {
$parrent = dirname($CFG->dataroot);
$i++;
if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
$CFG->dataroot = ''; //can not find secure location for dataroot
break;
}
$CFG->dataroot = dirname($parrent).'/moodledata';
}*/
Run Code Online (Sandbox Code Playgroud)
和
/* do {
if ($CFG->dataroot !== …Run Code Online (Sandbox Code Playgroud) 我试图想出一种从二叉树/二叉搜索树中删除重复项的算法。到目前为止我能想到的最好的是
将树的中序遍历存储在数组中。
如果树没有排序,则对数组进行排序。
从数组中删除重复项并重建二叉树。
我们是否还需要存储树的前序遍历来重建树?
O(n log n ) 这就带来了时间和空间上的复杂性 O(n)。我们可以做得更好吗?伪代码/代码示例将不胜感激
编辑1:假设二叉树的结构由以下对象给出
public class Node
{
int data;
Node right;
Node left;
// getters and setters for the left and right nodes
}
Run Code Online (Sandbox Code Playgroud) 我一直在尝试设置javac,但我不断收到可怕的错误消息
javac is not recognized as an internal or external command, operable program or batch file
Run Code Online (Sandbox Code Playgroud)
伊夫添加的javac的位置(C:\ Program Files文件\的Java\jdk1.7.0_17\bin)中的Path中Environment Variables..重新启动控制台等,但错误依然存在.我在这里错过了什么吗?
我是在 postgresql 和一般情况下编写存储函数的新手。我正在尝试使用输入参数写入 onw 并返回一组存储在临时表中的结果。我在我的函数中执行以下操作。1) 获取所有消费者的列表并将他们的 id 存储在临时表中。2)迭代特定表并从上述列表中检索与每个值对应的值并存储在临时表中。3)返回临时表。
这是我自己尝试编写的函数,
create or replace function getPumps(status varchar) returns setof record as $$ (setof record?)
DECLARE
cons_id integer[];
i integer;
temp table tmp_table;--Point B
BEGIN
select consumer_id into cons_id from db_consumer_pump_details;
FOR i in select * from cons_id LOOP
select objectid,pump_id,pump_serial_id,repdate,pumpmake,db_consumer_pump_details.status,db_consumer.consumer_name,db_consumer.wenexa_id,db_consumer.rr_no into tmp_table from db_consumer_pump_details inner join db_consumer on db_consumer.consumer_id=db_consumer_pump_details.consumer_id
where db_consumer_pump_details.consumer_id=i and db_consumer_pump_details.status=$1--Point A
order by db_consumer_pump_details.consumer_id,pump_id,createddate desc limit 2
END LOOP;
return tmp_table
END;
$$
LANGUAGE plpgsql;
Run Code Online (Sandbox Code Playgroud)
但是,我不确定我的方法,以及我是否在上面的代码中标记的 A 点和 B …
我是Python的新手,拥有Java背景.我遇到了以下函数定义
def S(seq,i=0):
print i
if i==len(seq):
return 0
return S(seq,i+1)+seq[i]
Run Code Online (Sandbox Code Playgroud)
这里到底做了i=0什么,每次重新初始化为0?因为我注意到i的值增加了.
"Hello - Debug" uses an invalid compiler. Probably the toolchain path within the compiler options is not setup correctly?! Skipping...
Run Code Online (Sandbox Code Playgroud)
当我尝试运行一个简单的HelloWorld程序时,我收到了上面的消息,如下所示。
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
关于为什么会发生这种情况以及我如何解决它的任何想法仅供参考:我目前使用 GNU GCC 编译器,我也尝试更改它,但没有用。
我正在尝试按照数据科学课程的介绍.但是我试图解析来自twitter的json响应时遇到了问题
我试图从以下格式的json中检索文本.
{u'delete': {u'status': {u'user_id_str': u'702327198', u'user_id': 702327198, u'id': 332772178690981889L, u'id_str': u'332772178690981889'}}}, {u'delete': {u'status': {u'user_id_str': u'864736118', u'user_id': 864736118, u'id': 332770710667792384L, u'id_str': u'332770710667792384'}}}, {u'contributors': None, u'truncated': False, **u'text'**: u'RT @afgansyah_reza: Lagi ngantri. Ada ibu2 & temennya. "Ih dia mukanya mirip banget sama Afgan.", trus ngedeketin gw, "Tuh kan.. Mirip bang\u2026', u'in_reply_to_status_id': None, u'id': 332772350640668672L, u'favorite_count': 0, ....... ]
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的代码:
def hw():
data = []
count=0
with open('output.txt') as f:
for line in f:
encoded_string = line.strip().encode('utf-8')
data.append(json.loads(encoded_string))
print data# generates the …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用返回表单中自定义列表的WCF服务List<StockData>.
以下是方法签名IService.cs:
[OperationContract]
List<StockData> orderStockData(string compName1, string compName2, string compName3);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试通过服务引用在我的网站中引用它时:
List<StockData> list = new List<StockData>();
list = myProxy.orderStockData(txtinput1.Text, txtinput2.Text, txtinput3.Text);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
无法将类型'ServiceReference1.StockData []'隐式转换为Systems.Collections.Generic.List
解决这个问题的任何帮助都会很棒.谢谢!