- 博客(26)
- 收藏
- 关注
原创 【temp】
238. Product of Array Except Self给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积。示例:输入: [1,2,3,4]输出: [24,12,8,6]说明: 请不要使用除法,且在 O(n) 时间复杂度内完成此题。进阶:...
2018-11-06 23:37:01
640
原创 【String】字符串类问题集合
242. Valid Anagram / 有效的字母异位词Given two strings s and t , write a function to determine if t is an anagram of s.给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词。Example 1:Input: s = "anagram", t = "...
2018-11-06 16:13:43
254
原创 【Leetcode】【BinarySearch】 4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).You may assume nums1 and ...
2018-11-05 19:57:01
259
原创 【二叉树code】总结
struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};二叉树的遍历:递归版本:void PreOrder(TreeNode* root) { if (root)...
2018-10-31 20:58:06
177
原创 【剑指Offer】 总结
链表类题目: 剑指Offer题6: 从尾到头打印链表输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。思路1: 使用栈的先入后出的思想,先遍历一遍并存入栈,后面再弹出保存即可 vector<int> printListFromTailToHead(ListNode* head) { // 定义一个栈 stac...
2018-10-19 22:44:48
207
原创 【DL与NLP】总结
为什么CNN可以文本分类?1,CNN的特性是用局部连接代替了全连接,CNN在2D的图像领域,前提假设是数据在二维空间上存在着局部相关性。如果输入不存在这个局部相关性,即shuffle也不影响,也就不适合用CNN了。文本语言中单个词单独看待和多个词组合的语义是有差别,即之间是有局部相关性的。文本上将一个句子embedding后得到二维特征矩阵,类似图像的应用,只是这里是一维窗口滚动,即...
2018-10-18 14:23:16
369
原创 【Math】数学类问题集合
Leetcode 7. Reverse IntegerGiven a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output...
2018-10-12 13:11:06
149
原创 【LeetCode】 【dp】 回文系列
以下几题:Leetcode 9. Palindrome Number给定一个数字,判断数字是否为回文数字。Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 121...
2018-09-29 19:01:07
215
原创 C++ 方法
string截取字符串:stringvar.substr(start , [length ])参数 stringvar 必选项。要提取子字符串的字符串文字或 String 对象。start 必选项。所需的子字符串的起始位置。字符串中的第一个字符的索引为 0。 length 可选项。在返回的子字符串中应包括的字符个数。 如果 length 为 0 或负数,将返回一个...
2018-09-23 11:39:43
804
原创 【Leetcode】【DP】 139. Word Break/分词
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.Note:The ...
2018-09-23 00:59:27
152
原创 【LeetCode 剑指Offer】 二叉树的最大与最小深度
求最大深度和最小深度。 最大深度题目:输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。 思路:1,一个二叉树的深度 = 以根节点为root的子树的深度 = max ( 以root->left为root的子树的深度, 以root->right为root的子树的深度 ) + 12,如果一...
2018-08-26 20:07:08
131
原创 【剑指offer】二叉树中和为某一值的路径
题目:输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。(注意: 在返回值的list中,数组长度大的数组靠前) 主要思想是使用DFS来解。 递归先序遍历树, 把结点加入路径。 若该结点是叶子结点则比较当前路径和是否等于期待和。 弹出结点,每一轮递归返回到父结点...
2018-08-26 19:38:14
102
原创 【Leetcode】【DFS】 112. Path Sum / 路经总和
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 sum.Note: A leaf is a node with no children.Example:Give...
2018-05-18 01:57:08
162
原创 【Leetcode】【链表】 19. Remove Nth Node From End of List / 删除链表的倒数第N个节点】
Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the li...
2018-05-15 01:02:27
184
原创 【Leetcode】【DP】 72. Edit Distance / 编辑距离
Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert a character Delete a chara...
2018-05-11 00:53:00
154
原创 【Leetcode】【DP-二维数组】 64. Minimum Path Sum / 最小路径和】
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any...
2018-05-11 00:07:36
443
原创 【Leetcode】【DP-二维数组】 63. Unique Paths II / 不同路径2(带障碍)
给定一个二维数组,每格为0/1值,1代表无法通过。求从左上到右下的不同路径数。只能往右/下走。Input:[ [0,0,0], [0,1,0], [0,0,0]]Output: 2Explanation:There is one obstacle in the middle of the 3x3 grid above.There are two ways to reach ...
2018-05-06 16:55:12
285
原创 【Leetcode】【DP-二维数组】 62. Unique Paths / 不同路径
给一个形状为m x n的矩阵,求从左上角到右下角的不同路径的个数。行进时只能往右/下移动。方法一:使用二维数组存储每个位置的dp值稍作画图分析即可得到dp式子:dp [i] [j] = dp [i-1] [j] + dp [i] [j-1](1)首先,可知若只能往下或往右走,则只能有一条路径。可以先将第一行与第一列进行赋值,再通过循环计算其他格的dp值,防止 i-1 或 j-1 非法(当前i, j...
2018-05-06 00:35:28
265
原创 【剑指 offer】 链表中倒数第k个结点
输入一个链表,输出该链表中倒数第k个结点。思想有两种一种是考虑到取倒数,可采用栈的形式先整体读入,然后再pop出栈第k个。另一种是使用两个指针栈,两个指针相差k位,然后同时移动,直到后面的指针到达链表尾节点,此时前一个节点即是为需要求的倒数第k个结点。(1)首先定义两个指针为p1,p2(2)将p2先往前行走 k - 1 步(k-1才会得到倒数第k个)。操作时要注意是否出现k比链表长度还大。所以在行...
2018-04-29 14:04:01
101
原创 【剑指offer】 反转链表
输入一个链表头节点,反转链表,并输出反转后的链表头节点。考虑从头开始遍历,每次记录当前节点及前后三个位置的节点,然后将当前节点的next指向上一节点(完成当前的反转),再移动到下一个节点操作。最开始,将prior置为空,然后curr为头节点。首先,记录下一个节点next再将curr连至prior再讲prior更新到curr处,curr更新到next处循环上述步骤直至curr为空(即操作到尾节点后,...
2018-04-25 21:07:54
113
原创 【剑指offer】二叉树的下一个节点
给出一棵二叉树和一个节点,求中序遍历序列的下一个节点。二叉树结构是给出了左右节点以及父节点的。首先分析中序遍历,中序遍历即左父右的顺序遍历树。分析规律:(1)节点存在右节点 if(p->right)则不断检查p->right是否还有左节点,若没有左节点了,该节点即为res。 if(pNode->right) // 若存在右节点 { ...
2018-04-25 21:07:46
130
原创 LeetCode 20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all valid but ...
2018-04-25 21:07:27
80
原创 DP
53. Maximum Subarray求连续子序列的最大和。DP分析:1, dp[0] = nums[0]2, dp[1] = max (nums[0], nums[1]) dp[2] = max (dp[1]+nums[2], nums[2])由此可推:dp[i] = max( dp[i-1] + nums[i] , nums[i])维护一个max,取得最大的dp值即可。此方法在lee...
2018-04-25 21:07:14
201
原创 DFS
100. Same Tree判定为same tree,由结构+val决定。使用DFS,先到达最下方的叶节点,判断是否都为nullptr,然后再结合节点的val值。对于树,由于会涉及比对val,所以先把节点为空的情况判断完全。此题中,1、两点均为空节点。即相同且已经走到了叶节点,返回true(之前都没return false说明之前符合,到这一步也就符合了)2、两节点有一个为空节点。返回false,...
2018-04-25 21:06:52
204
原创 基本算法(一)-插入排序 InsertSort的C++实现
插入排序是最直接的排序方式之一,Algorithms.4 中举例为抓扑克牌时,从左到右将最小的扑克牌放置在最左,依次进行。void vInsertSort(vector<int> &nums){ int len = nums.size(); int temp; for(int i=0; i<len-1; i++){ // i从第一个到倒数第二个 ...
2018-03-30 18:48:23
606
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人