temp

csdn_export_md

耗尽温柔 提交于 2019-12-12 00:12:34
在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序。 示例 1: 输入: 4->2->1->3 输出: 1->2->3->4 示例 2: 输入: -1->5->3->4->0 输出: -1->0->3->4->5 首先归并排序 public static void mergeSort(int[] arr) { sort(arr, 0, arr.length - 1); } public static void sort(int[] arr, int L, int R) { if(L == R) { return; } int mid = L + ((R - L) >> 1); sort(arr, L, mid); sort(arr, mid + 1, R); merge(arr, L, mid, R); } public static void merge(int[] arr, int L, int mid, int R) { int[] temp = new int[R - L + 1]; int i = 0; int p1 = L; int p2 = mid + 1; // 比较左右两部分的元素,哪个小,把那个元素填入temp中 while(p1 <= mid && p2 <= R) { temp[i++] = arr[p1] < arr[p2] ?

如何随机化(随机播放)JavaScript数组?

跟風遠走 提交于 2019-12-11 19:26:04
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我有一个像这样的数组: var arr1 = ["a", "b", "c", "d"]; 如何随机/随机播放? #1楼 一个人可以(或应该)将其用作Array的原型: 来自ChristopheD: Array.prototype.shuffle = function() { var i = this.length, j, temp; if ( i == 0 ) return this; while ( --i ) { j = Math.floor( Math.random() * ( i + 1 ) ); temp = this[i]; this[i] = this[j]; this[j] = temp; } return this; } #2楼 这是 Durstenfeld shuffle 的JavaScript实现, Durstenfeld shuffle 是Fisher-Yates的计算机优化版本: /** * Randomize array element order in-place. * Using Durstenfeld shuffle algorithm. */ function shuffleArray(array) { for (var i = array.length - 1; i > 0

Temporary files & folders on Windows

时间秒杀一切 提交于 2019-12-11 16:24:10
问题 Emulating multithreading by loading a DLL multiple times (it's designed for this). Since LoadLibrary() doesn't really allow it, the DLL copies itself into a temporary file, via GetTempPath() and GetTempFileName() . It's a small file and upon thread destruction it frees the library and deletes the temporary file. Problem now is that the number of threads is configurable (maniacs can pick 50, 100, more) which basically exposes the risk of running unstable, crash and not go through the usual

leetcode-n2-两数相加

怎甘沉沦 提交于 2019-12-11 16:00:27
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> leetcode-两数相加 下面的类,可以重用,修改一下可以运行在在线IDE,给出了测试 main() 题目源地址 提交记录 /* 给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。 如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。 您可以假设除了数字 0 之外,这两个数都不会以 0 开头。 示例: 输入:(2 -> 4 -> 3) + (5 -> 6 -> 4) 输出:7 -> 0 -> 8 原因:342 + 465 = 807 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/add-two-numbers 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 */ /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class ListNode { int val; ListNode next; ListNode(int x)

Windows Tensorflow with Python unable to read mnist data due to permissions

拥有回忆 提交于 2019-12-11 05:55:27
问题 I'm using Python on windows and am following the standard tutorial for Tensorflow that requires reading the MNIST data set. Unfortunately I get the following error when trying to run: PermissionError: [Errno 13] Permission denied: 'C:\Users\matth\AppData\Local\Temp\tmp6_cvro98' That filename at the end changes each time the program runs. The code in question is: import tensorflow as tf from tensorflow.contrib.learn.python.learn.datasets import mnist as input_data mnist = input_data.read_data

Pythonic way to append output of function to several lists

霸气de小男生 提交于 2019-12-11 05:39:59
问题 I have a question that I haven't quite found a good solution to. I'm looking for a better way to append function output to two or more lists, without using temp variables. Example below: def f(): return 5,6 a,b = [], [] for i in range(10): tmp_a, tmp_b = f() a.append(tmp_a) b.append(temp_b) I've tried playing around with something like zip(*f()), but haven't quite found a solution that way. Any way to remove those temp vars would be super helpful though, thanks! Edit for additional info: In

LeetCode:合并K个排序链表

风流意气都作罢 提交于 2019-12-11 00:54:32
题目: 合并 k 个排序链表,返回合并后的排序链表。请分析和描述算法的复杂度。 示例: 输入: [ 1->4->5, 1->3->4, 2->6 ] 输出: 1->1->2->3->4->4->5->6 我的答案: 解法一:暴力法 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public ListNode mergeKLists(ListNode[] lists) { //ListNode node = new ListNode(0); if(lists==null||lists.length==0){ return null; } //node.next = lists.get(0); ListNode temp = lists[0]; for(int i=1;i<lists.length;i++){ temp = mergeTwoLists(temp,lists[i]); } return temp; } public ListNode mergeTwoLists(ListNode l1,ListNode l2){

数据机构学习(链表)

血红的双手。 提交于 2019-12-10 22:15:22
链表: 以节点的方式来存储 每个节点包含data域,next域:指向下一个节点 各个节点不一定连续存储 分为带头节点和不带头节点(根据实际需求确定) head节点: 不存放具体数据,作用就是表示单链表的头 //单链表 public class SingleLinkedListDemo { public static void main(String[] args) { //创建几个节点 HeroNode hero1 = new HeroNode(1, "萧炎", "炎帝"); HeroNode hero2 = new HeroNode(2, "叶凡", "叶天帝"); HeroNode hero3 = new HeroNode(3, "韩立", "韩老魔"); HeroNode hero4 = new HeroNode(4, "石昊", "荒天帝"); //创建链表 SingleLinkedList singleLinkedList = new SingleLinkedList(); //加入 // singleLinkedList.add(hero1); // singleLinkedList.add(hero2); // singleLinkedList.add(hero3); // singleLinkedList.add(hero4); //加入按照编号的顺序(自动排序)

Get temperature from NVidia GPU using NVAPI

余生长醉 提交于 2019-12-10 19:55:10
问题 I have been trying for the last few days to get the temperature of my GPU using C++ using the NVAPI i have the following code #include "stdafx.h" #include "nvapi.h" int _tmain(int argc, _TCHAR* argv[]) { NvAPI_Status ret = NVAPI_OK; int i=0; NvDisplayHandle hDisplay_a[NVAPI_MAX_PHYSICAL_GPUS*2] = {0}; ret = NvAPI_Initialize(); if (!ret == NVAPI_OK){ NvAPI_ShortString string; NvAPI_GetErrorMessage(ret, string); printf("NVAPI NvAPI_Initialize: %s\n", string); } NvAPI_ShortString ver; NvAPI

解数独算法

筅森魡賤 提交于 2019-12-10 19:19:14
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 完善填数解数独 #include<stdio.h> #include<string.h> struct Avaliable { short row; short col; }; int OnlyAvaliable(short n) { return n!= 0 && ( n & ( n - 1 ) ) == 0; } int PointAvaliable(short n) { return n?PointAvaliable(n & ( n - 1 ))+1:0; } int getHighBit(short n) { int i = 0; while(n) { n/=2; i++; } return i-1; } Avaliable g_avas[9][9]; int g_solved = 0; unsigned short g_SudokuMap[9][9] = { // {1,3,0,0,6,8,0,0,0}, // {6,0,0,0,0,0,0,8,1}, // {5,0,0,0,4,0,2,0,0}, // {3,0,0,7,0,2,0,0,0}, // {4,1,7,0,8,0,3,5,2}, // {0,0,0,1,0,4,0,0,9}, // {0,0,4,0,7,0,0,0,8}, // {2