摘要:题目描述 给你二叉搜索树的根节点 root ,该树中的两个节点被错误地交换。请在不改变其结构的情况下,恢复这棵树。 示例 2: 输入: [3,1,4,null,null,2] 3 / \66 1 4 / 2 输出: [2,1,4,null,null,3] 2 / \ 1 4 / 3 进阶: 使用 O
阅读全文
摘要:题目描述 Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows: The left subtree of a node contains
阅读全文
摘要:题目描述 给定一个二叉搜索树,编写一个函数 kthSmallest 来查找其中第 k 个最小的元素。 说明: 你可以假设 k 总是有效的,1 ≤ k ≤ 二叉搜索树元素个数。 示例 1: 输入: root = [3,1,4,null,2], k = 1 3 / \ 1 4 \ 2 输出: 1 示例
阅读全文
摘要:题目描述 Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your lastvious solutio
阅读全文
摘要:题目描述 Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate(填充) each next pointer to point
阅读全文
摘要:题目描述 Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree. For example: Given the below binary tree, 1 /
阅读全文
摘要:题目描述 Given a binary tree, return the bottom-up level order traversal of its nodes values. (ie, from left to right, level by level from leaf to root).
阅读全文
摘要:题目描述 给定一个二叉树,找出其最小深度。 最小深度是从根节点到最近叶子节点的最短路径上的节点数量。 说明: 叶子节点是指没有子节点的节点。 示例: 给定二叉树 [3,9,20,null,null,15,7], 3 / 9 20 / 15 7 返回它的最小深度 2. /** * Definition
阅读全文
摘要:题目描述 Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthe
阅读全文
摘要:题目描述 Given a binary tree, return the zigzag level order traversal f its nodes values.(ie, from left to right, then right to left for the next level an
阅读全文
摘要:题目描述 Given a binary tree, 返回 the level order traversal of its nodes values.(ie, from left to right,level by level). For example: Given binary tree{3,9
阅读全文
摘要:题目描述 Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the
阅读全文
摘要:题目描述 找出所有相加之和为 n 的 k 个数的组合。组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字。 说明: 所有数字都是正整数。解集不能包含重复的组合。 示例 1: 输入: k = 3, n = 7 输出: [[1,2,4]] 示例 2: 输入: k = 3, n = 9
阅读全文
摘要:题目描述 Given a collection of candidate numbers ( C ) and a target number ( T ),find all unique combinations in C where the candidate numbers sums to T .
阅读全文
摘要:题目描述 Given a set of candidate numbers ( C ) and a target number ( T ),find all unique combinations in C where the candidate numbers sums to T .The sam
阅读全文
摘要:题目描述 给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合。 示例: 输入: n = 4, k = 2 输出: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] 方法1 思路 没有剪枝的暴力dfs 以1-n这n个位置的情况进行遍历
阅读全文
摘要:题目描述 给定一个整数 n,返回 n! 结果尾数中零的数量。 示例 1: 输入: 3 输出: 0 解释: 3! = 6, 尾数中没有零。 示例 2: 输入: 5 输出: 1 解释: 5! = 120, 尾数中有 1 个零. 说明: 你算法的时间复杂度应为 O(log n) 。 思路 其实也就是求阶乘
阅读全文
摘要:题目描述 给定一个包含 0, 1, 2, ..., n 中 n 个数的序列,找出 0 .. n 中没有出现在序列中的那个数。 示例 1: 输入: [3,0,1] 输出: 2 示例 2: 输入: [9,6,4,2,3,5,7,0,1] 输出: 8 说明: 你的算法应具有线性时间复杂度。你能否仅使用额外
阅读全文
摘要:题目描述 给定一个整数数组 nums,其中恰好有两个元素只出现一次,其余所有元素均出现两次。 找出只出现一次的那两个元素。 示例 : 输入: [1,2,1,3,2,5] 输出: [3,5] 注意: 结果输出的顺序并不重要,对于上面的例子, [5, 3] 也是正确答案。你的算法应该具有线性时间复杂度。
阅读全文
摘要:题目描述 Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear run
阅读全文
摘要:题目描述: Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime
阅读全文
摘要:题目描述 反转一个单链表。 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 进阶: 你可以迭代或递归地反转链表。你能否用两种方法解决这道题? /** * Definition for singly-linked list. * struct L
阅读全文
摘要:题目描述 You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can yo
阅读全文
摘要:题目描述 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2
阅读全文
摘要:题目描述 Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identic
阅读全文
摘要:题目描述 Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 uniqu
阅读全文
摘要:题目描述 Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should retu
阅读全文
摘要:题目描述 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. /** * Definition for singly-linked
阅读全文
摘要:题目描述 Given an array where elements are sorted in ascending order,convert it to a height balanced BST. /** * Definition for binary tree * struct TreeNo
阅读全文
摘要:题目描述 Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. /** *
阅读全文
摘要:题目描述 Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. /** * D
阅读全文
摘要:题目描述 Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are no
阅读全文
摘要:题目描述 将一个给定字符串根据给定的行数,以从上往下、从左到右进行 Z 字形排列。比如输入字符串为 "LEETCODEISHIRING" 行数为 3 时,排列如下: L C I R E T O E S I I G E D H N 之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:"LC
阅读全文
摘要:题目描述 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. /**
阅读全文
摘要:题目描述 Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k =2,return 4->5->1->
阅读全文
摘要:题目描述 Given a linked list, remove the n th node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. Aft
阅读全文
摘要:题目描述 给定一个单链表 L:L0→L1→…→Ln-1→Ln ,将其重新排列后变为: L0→Ln→L1→Ln-1→L2→Ln-2→…你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。 示例 1: 给定链表 1->2->3->4, 重新排列为 1->4->2->3. 示例 2: 给定链表
阅读全文
摘要:题目描述 请判断一个链表是否为回文链表。 示例 1: 输入: 1->2 输出: false 示例 2: 输入: 1->2->2->1 输出: true 进阶: 你能否用 O(n) 时间复杂度和 O(1) 空间复杂度解决此题? /** * Definition for singly-linked li
阅读全文
摘要:题目描述 删除链表中等于给定值 val 的所有节点。 示例: 输入: 1->2->6->3->4->5->6, val = 6 输出: 1->2->3->4->5 /** * Definition for singly-linked list. * struct ListNode { * int v
阅读全文
摘要:题目描述 请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点,你将只被给定要求被删除的节点。 现有一个链表 -- head = [4,5,1,9],它可以表示为: 示例 1: 输入: head = [4,5,1,9], node = 5 输出: [4,1,9] 解释: 给定你链表中值为 5
阅读全文
摘要:题目描述 编写一个程序,找到两个单链表相交的起始节点。 如下面的两个链表: 在节点 c1 开始相交。 示例 1: 输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3 输出:Refe
阅读全文
摘要:题目描述 Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3
阅读全文
摘要:题目描述 Given a binary tree and a sum, find all root-to-leaf paths where each paths sum equals the given sum. For example: Given the below binary tree an
阅读全文
摘要:题目描述 Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given s
阅读全文
摘要:题目描述 翻转一棵二叉树。 示例: 输入: 4 / 2 7 / \ / 1 3 6 9 输出: 4 / 7 2 / \ / 9 6 3 1 备注: 这个问题是受到 Max Howell 的 原问题 启发的 : 谷歌:我们90%的工程师使用您编写的软件(Homebrew),但是您却无法在面试时在白板上
阅读全文
摘要:概述 BERT的全称是Bidirectional Encoder Representation from Transformers,是论文BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding中
阅读全文
摘要:概述 Open AI GPT是OpenAI 团队在论文Improving Language Understanding by Generative Pre-Training中提出的预训练语言模型,他们的目标是学习一个通用的表示,能够在大量任务上进行应用。核心思想是先通过无标签的文本去训练生成语言模型
阅读全文
摘要:无论是n-gram语言模型(unigram, bigram, tirgram),还是理论上可以记忆无限个单词的无穷元语法(∞-gram)和递归神经网络语言模型(RNN Language Model),都会涉及到一个最关键的问题:如何来评价这些语言模型的好坏? 语言模型是很多涉及到产生文字或预测文字概
阅读全文
摘要:概述 2018年,论文《Deep Contextualized(语境化) Word Representations》中提出了ELMo,即Embeddings from Language Models。作者认为一个预训练的词表示应该具备以下特点: 能够包含丰富的句法和语义信息 能够对多义词进行建模。
阅读全文
摘要:语言模型简单来说就是一串词序列的概率分布。具体来说,语言模型的作用是为一个长度为m的文本确定一个概率分布P,表示这段文本存在的可能性。在实践中,如果文本的长度较长,$P(w_i | w_1, w_2, . . . , w_{i−1})$的估算会非常困难。因此,研究者们提出使用一个简化模型:n元模型(
阅读全文
摘要:对应的英文地址The Illustrated Transformer 概述 前一段时间谷歌推出的BERT模型在11项NLP任务中夺得SOTA结果,引爆了整个NLP界。而BERT取得成功的一个关键因素是Transformer的强大作用。谷歌的Transformer模型最早是用于机器翻译任务,当时达到了
阅读全文
摘要:在我们使用transformers进行预训练模型学习及微调的时候,我们需要先对数据进行预处理,然后经过处理过的数据才能“喂”进bert模型里面,这这个过程中我们使用的主要的工具就是tokenizer。你可以建立一个tokenizer通过与相关预训练模型相关的tokenizer类,例如,对于Rober
阅读全文
摘要:通常我们在利用Bert模型进行NLP任务时,需要针对特定的NLP任务,在Bert模型的下游,接上针对特定任务的模型,因此,我们就十分需要知道Bert模型的输出是什么,以方便我们灵活地定制Bert下游的模型层,本文针对Bert的一个pytorch实现transformers库,来探讨一下Bert的具体
阅读全文