首页
学习
活动
专区
工具
TVP
发布

Bingo的深度学习杂货店

专栏作者
183
文章
152329
阅读量
43
订阅数
三个数的和小于等于k
给一个数组以及一个数K, 从这个数组里面选择三个数,使得三个数的和小于等于K, 有多少种选择的方法?(不包括重复的情况) Example: Input: nums = [3,2,5,2,1,4,2,3] k = 7 Output: 6 # [1,2,4], [1,2,3], [1,2,2], [1,3,3], [2,2,2], [2,2,3] 解题思路: 这个题是“三个数的和等于K”的变形,主要难点在于去重。首先,还是先列表从小到大排序,然后外循环遍历 nums[0...n-2],将三个数问题转化为两个
echobingo
2018-04-25
1.5K0
KMP 算法
题目描述:Leetcode 28. Implement strStr() 之前在 Leetcode 上 AC 的 O(MN) 版本:Q28 Implement strStr() 解题思路: KMP 算法是经典的求解子串(模式串)出现在主串中位置的算法,也是数据结构当时学习的一个知识点。它因为在匹配过程中,主串下标不后退,而可以使时间复杂度从 O(MN) 降为 O(M+N) 。之前学过忘了,现在在此做一个总结。 KMP 算法的关键:求出子串(模式串)的 next 数组。 举例: 子串 pattern 下标
echobingo
2018-04-25
8110
最小方差划分
给一个数组,求一个k值,使得前k个数的方差 + 后面n-k个数的方差最小 解题思路: 如果不考虑方差的概念,这题可以简化为 “给一个数组,求一个k值,使得前k个数的和 + 后面n-k个数的和最小”。 举例, 如 nums = [1,3,2,4],我们可以先从左向右求出各个子段和 [1,4,6,10],然后再从右向左求出各个子段和 [4,6,9,10],我们发现对应的子段和为 1 -> 9, 4 -> 6, 6 -> 4。因此,我们只需要正反遍历数组两次,就可以求得结果。 时间复杂度:O(n),空间复杂度 O
echobingo
2018-04-25
3.3K0
《机器学习实战》总结篇
前些天完成了《机器学习实战》这本书的学习,也利用 Python3 实现了各个章节的代码,对传统的机器学习方法有了更进一步的了解,这里做一个总结。 代码传送门: https://github.com/xyxxmb/Machine-Learning-In-Action 目录 第一部分:分类 【Ch1】机器学习基础 【Ch2】k - 近邻算法 【Ch3】决策树 【Ch4】基于概率论的分类方法:朴素贝叶斯 【Ch5】Logistic 回归 【Ch6】支持向量机 【Ch7】利用 AdaBoost 元算法
echobingo
2018-04-25
8610
Q202 Happy Number
Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equ
echobingo
2018-04-25
4970
Q198 House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatical
echobingo
2018-04-25
4510
Q167 Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be
echobingo
2018-04-25
4140
Q107 Binary Tree Level Order Traversal II
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). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its bo
echobingo
2018-04-25
3720
Q111 Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 解题思路: 先明白最小路径的定义:从根结点到最近叶子结点的所包含的结点个数(包括根)。 举个例子: Example1: 0 return 1 Example2: 0
echobingo
2018-04-25
3660
Q101 Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following [1,2,2,null,3,null,3] is not: 1 /
echobingo
2018-04-25
4890
Q67 Add Binary
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 解题思路: 使用Python的内置函数 .zfill(总长度) 将 a、b两字符串补为相等的字符串,然后从后往前相加。 Python实现: class Solution: def addBinary(self, a, b): """ :type
echobingo
2018-04-25
4980
Q20 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 "(]" and "([)]" are not. 解题思路: 模拟栈的操作,如果是(、[、},则入栈;如果是
echobingo
2018-04-25
4980
Q35 Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Example 1: Input: [1,3,5,6], 5 Output: 2 Example 2: Input:
echobingo
2018-04-25
5280
Q28 Implement strStr()
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example 1: Input: haystack = "hello", needle = "ll" Output: 2 Example 2: Input: haystack = "aaaaa", needle = "bba" Output: -1 解题思路:
echobingo
2018-04-25
5210
Q21 Merge Two Sorted Lists
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. Example: Input: 1->2->4, 1->3->4 Output: 1->1->2->3->4->4 解题思路: 创建一个新链表,包括头结点和工作结点。在比较的过程中为工作结点的后续创建新的结点,直至有一个链表为空
echobingo
2018-04-25
5230
Q26 Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Example: G
echobingo
2018-04-25
4570
Q27 Remove Element
Given an array and a value, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be ch
echobingo
2018-04-25
6080
Q13 Roman to Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 解题思路: 将罗马字符保存到map中,观察罗马字符的规律,编写代码。 Python实现: class Solution: def romanToInt(self, s): """ :type s: str :rtype: int
echobingo
2018-04-25
5390
Q7 Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 Note: Assume we are dealing with an environment which could only hold integers within the
echobingo
2018-04-25
5230
Q1 Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: Given nums = [2, 7, 11, 15], targ
echobingo
2018-04-25
5040
点击加载更多
社区活动
腾讯技术创作狂欢月
“码”上创作 21 天,分 10000 元奖品池!
Python精品学习库
代码在线跑,知识轻松学
博客搬家 | 分享价值百万资源包
自行/邀约他人一键搬运博客,速成社区影响力并领取好礼
技术创作特训营·精选知识专栏
往期视频·千货材料·成员作品 最新动态
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档