我正在尝试制作一个算法,找到将目标插入已排序数组的最佳位置.
目标是返回项目的位置(如果它存在于列表中),否则返回它将保持列表排序的位置.
所以说我有一个清单:
0 1 2 3 4 5 6
---------------------------------
| 1 | 2 | 4 | 9 | 10 | 39 | 100 |
---------------------------------
Run Code Online (Sandbox Code Playgroud)
而我的目标项是14
它应该返回索引位置5
伪代码我目前有:
array = generateSomeArrayOfOrderedNumbers()
number findBestIndex(target, start, end)
mid = abs(end - start) / 2
if (mid < 2)
// Not really sure what to put here
return start + 1 // ??
if (target < array[mid])
// The target belongs on the left side of our …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个工作流助手,需要从几个不同的映射网络驱动器中获取文件/执行命令.
我有3个单独的映射驱动器.Z:\ Y:\和W:\(以及我的C:\)
当我尝试按照以下方式做某事时:
Directory.SetCurrentDirectory("Z:\\xampp\\htdocs");
Console.WriteLine(Environment.CurrentDirectory);
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
它工作得很好.它将Z:\xampp\htdocs按照应有的方式输出.
但是,如果我再次运行完全相同的代码但具有管理员权限,它会给我一个System.IO.DirectoryNotFoundException例外.