OneCoder


  • 首页

  • 归档

  • 标签

  • 关于

  • 搜索

LeetCode Intersection of Two Linked List

发表于 2017-12-15 | 阅读次数

Problem

Write a program to find the node at which the intersection of two singly linked lists begins.

For example, the following two linked lists:

A:          a1 → a2
                   ↘
                     c1 → c2 → c3
                   ↗            
B:     b1 → b2 → b3

begin to intersect at node c1.

Notes:

If the two linked lists have no intersection at all, return null. The linked lists must retain their original structure after the function returns. You may assume there are no cycles anywhere in the entire linked structure. Your code should preferably run in O(n) time and use only O(1) memory.

即找到两个链表相交的第一个元素。要求不改变链表结构,O(n)时间, O(1)内存

阅读全文 »

LeetCode Min Stack

发表于 2017-12-14 | 阅读次数

Problem

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top element. getMin() – Retrieve the minimum element in the stack. Example:

MinStack minStack = new MinStack();
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
minStack.getMin();   --> Returns -3.
minStack.pop();
minStack.top();      --> Returns 0.
minStack.getMin();   --> Returns -2.

即自定义一个栈,除了支持栈的基本操作外,支持一个额外的getMin返回当前栈内元素最小值的操作。

阅读全文 »

LeetCode Linked List Cycle II

发表于 2017-12-13 | 阅读次数

Problem

Given a linked list, return the node where the cycle begins. If there is no cycle, return null.

Note: Do not modify the linked list.

Follow up: Can you solve it without using extra space?

找到链表中环的入口节点,不开辟额外空间

阅读全文 »

LeetCode Linked List Cycle

发表于 2017-12-12 | 阅读次数

Problem

Given a linked list, determine if it has a cycle in it.

Follow up: Can you solve it without using extra space?

判断一个链表中是否存在 环,不开辟额外的空间

阅读全文 »

LeetCode Single Number II

发表于 2017-12-11 | 阅读次数

Problem

Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one.

Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

一个整型数组,除一个元素外,其余的元素都出现三次,要求不用额外内存,线性时间内找到这个元素

阅读全文 »

LeetCode Single Number

发表于 2017-12-07 | 阅读次数

Problem

Given an array of integers, every element appears twice except for one. Find that single one.

Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

一个整型数组,除一个元素外,其余的元素都出现两次,要求不用额外内存,线性时间内找到这个元素

阅读全文 »

LeetCode Valid Palindrome

发表于 2017-12-06 | 阅读次数

Problem

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

For example, “A man, a plan, a canal: Panama” is a palindrome. “race a car” is not a palindrome.

Note: Have you consider that the string might be empty? This is a good question to ask during an interview.

For the purpose of this problem, we define empty string as valid palindrome.

即判断一个字符串的字符部分是不是回环字符串。即出去非字母,数字以外的字符,剩下的部分满足正反相同。

阅读全文 »

LeetCode Best Time to Buy and Sell Stock II

发表于 2017-12-06 | 阅读次数

Problem

Say you have an array for which the ith element is the price of a given stock on day i.

Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

上一个问题的变形,即求累计利润的最大值。就是按顺序相减的和。

阅读全文 »

LeetCode Best Time to Buy and Sell Stock

发表于 2017-12-06 | 阅读次数

Problem

Say you have an array for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Example 1:

Input: [7, 1, 5, 3, 6, 4]
Output: 5

max. difference = 6-1 = 5 (not 7-1 = 6, as selling price needs to be larger than buying price)

Example 2:

Input: [7, 6, 4, 3, 1]
Output: 0

In this case, no transaction is done, i.e. max profit = 0.

即给定一个数组,按从前往后顺序计算,求最大差。

阅读全文 »

TensorFlow's Hello World Mnist数据集下载错误问题解决

发表于 2017-12-05 | 阅读次数

部署Anaconda 科学计算包,并通过

conda install -c conda-forge tensorflow

部署tensorflow相关包。在ipython环境下执行下列命令下载训练数据包

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

结果报错,

[Errno 104] Connection reset by peer

错误信息

阅读全文 »
1 … 6 7 8 … 33
LiHongZhe

LiHongZhe

onecoder's blog.

326 日志
8 分类
RSS
Creative Commons
Links
  • 酷壳
  • 酸菜鱼
  • 私塾在线学习网
  • 煮酒品茶
  • 点滴技术博客
  • 思考者日记网·束洋洋
  • 开源视窗
  • 小弟子的网络之路
  • 寄存心–移动开发
  • TicmyBlog
  • 中国程序员人才网
  • 图表秀-在线图表制作
  • IT热血青年
© 2012 - 2022 LiHongZhe
由 Jekyll 强力驱动
主题 - NexT.Muse