
LeetCode
PartyPartyAnimal
这个作者很懒,什么都没留下…
展开
-
tf.train.batch()和tf.train.shuffle_batch()函数
tf.train.batch([example, label], batch_size=batch_size, capacity=capacity) [example, label]表示样本和样本标签 batch_size是返回的一个batch样本集的样本个数 capacity是队列中的容量。这主要是按顺序组合成一个batchtf.train.shuffle_batch([example, l原创 2017-09-07 17:17:01 · 1853 阅读 · 0 评论 -
4. Median of Two Sorted Arrays
findKth(A,B,k)函数思路如下: 1. 保持A是短的那一个数组,B是长的 2. 平分k, 一半在A,一半在B (如果A的长度不足K/2,那就pa就指到最后一个) 3. 如果pa的值 < pb的值,那证明第K个数肯定不会出现在pa之前,递归,把A数组pa之前的砍掉,同理递归砍B数组。 4. 递归到 m == 0 (短的数组用完了) 就返回 B[k - 1], 或者k == 1(找第一原创 2017-08-30 20:30:39 · 315 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the le原创 2017-08-30 11:20:16 · 259 阅读 · 0 评论 -
2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it原创 2017-08-18 16:45:59 · 253 阅读 · 0 评论 -
1. 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 ele原创 2017-08-18 16:13:54 · 225 阅读 · 0 评论 -
20. Valid Parentheses
Python:class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ stack = [None] #用来依次存储左括号 #用栈来操作原创 2017-07-21 11:56:53 · 261 阅读 · 0 评论 -
22. Generate Parentheses
分析: 递归实现,如果左括号还有剩余,则可以放置左括号,如果右括号的剩余数大于左括号,则可以放置右括号。Python:class Solution(object): def generateParenthesis(self, n): """ :type n: int :rtype: List[str] """原创 2017-07-21 10:30:20 · 260 阅读 · 0 评论 -
16. 3Sum Closest
思路: 先任意取三元素和res;记录和目标的差值diff 每次取一个数,在后续列表中找2个元素,满足三数之和最接近target,通过判断三数之和和目标的差值和diff大小,小于diff则将三数之和和差值赋值给res和diff,然后再分析和小于移动左指针,大于移动右指针,直到遍历找到最接近的数 Python:class Solution(object): def threeSumClose原创 2017-07-20 12:15:54 · 255 阅读 · 0 评论 -
15. 3Sum
python:class Solution(object): def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ res = [] nums.sort() #先对数组原创 2017-07-18 16:05:46 · 312 阅读 · 0 评论 -
14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. Python:class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str]原创 2017-07-17 11:00:34 · 309 阅读 · 0 评论 -
8. String to Integer (atoi)
class Solution(object): def myAtoi(self, str): """ :type str: str :rtype: int """ i = 0 sign = 1 base = 0 n = len(str) INT_原创 2017-07-15 21:11:52 · 373 阅读 · 0 评论