torch.topk torch.topk(input, k, dim=None, largest=True, sorted=True, out=None) -> (Tensor, LongTensor) pytorch中文官网文档:http://www.mamicode.com/info-deta ...
分类:
其他好文 时间:
2020-03-14 22:02:14
阅读次数:
101
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note:You may assume k is always valid, 1 ≤ k ≤ BST's ...
分类:
其他好文 时间:
2020-03-12 10:13:11
阅读次数:
82
Input: [2,3,-2,4] Output: 6 Explanation: [2,3] has the largest product 6. Input: [2,-5,-2,-4,3] Output: 24 Explanation: [-2,-4,3] has the largest prod ...
分类:
其他好文 时间:
2020-03-07 13:08:31
阅读次数:
54
剑指offer 62.二叉搜索树的第k个结点 题目 给定一棵二叉搜索树,请找出其中的第k小的结点。例如, (5,3,7,2,4,6,8) 中,按结点数值大小顺序第三小结点的值为4。 思路 二叉搜索树的中序遍历是递增的,找到第k小的话,那就只需要中序遍历即可,遍历的第k个数就是所需的数。 代码 ...
分类:
其他好文 时间:
2020-03-06 15:37:32
阅读次数:
53
1、题目 Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row index starts from 0. In Pascal's ...
分类:
其他好文 时间:
2020-03-02 01:09:35
阅读次数:
82
题目: 给定由一些正数(代表长度)组成的数组 A,返回由其中三个长度组成的、面积不为零的三角形的最大周长。 如果不能形成任何面积不为零的三角形,返回 0。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/largest-perimeter-tr ...
分类:
编程语言 时间:
2020-02-29 22:30:56
阅读次数:
136
14.链表中倒数第k个结点 题目 输入一个链表,输出该链表中倒数第k个结点。 思路 假设原链表有n个结点,倒数第k个结点就是n k+1个结点,那么这里可以设置两个结点,一个结点先走k 1步,是第k个结点,然后两个结点一起走,第一个结点再走n k步就到达末尾,此时第二个结点也走了n k步,到达了n k ...
分类:
其他好文 时间:
2020-02-28 11:44:10
阅读次数:
44
题目: 链接:https://leetcode-cn.com/problems/largest-divisible-subset/ 给出一个由无重复的正整数组成的集合,找出其中最大的整除子集,子集中任意一对 (Si,Sj) 都要满足:Si % Sj = 0 或 Sj % Si = 0。 如果有多个目 ...
分类:
其他好文 时间:
2020-02-26 01:33:16
阅读次数:
56
``` class Solution { public int findKthLargest(int[] nums, int k) { PriorityQueue h = new PriorityQueue((n1,n2)->n1-n2); for(int i:nums){ h.add(i); if... ...
分类:
其他好文 时间:
2020-02-24 00:46:36
阅读次数:
80
"题目" 题意:找到一个数组里第K大的数字。 题解:我们当然可以排序好了,之后,选择第K大的数字。但是这样做一点技术含量也没有。 排序算法选用快排。寻找第K大的数字,不必把数组完全排完序之后,再找第K大。快排中是选取一个数字,把大于它的放在右边,小于它的放在左边,在递归的时候,我们判断k 和右边数字 ...
分类:
编程语言 时间:
2020-02-22 13:39:48
阅读次数:
58