PikachuBLOG


  • 首页

  • 分类

  • 归档

  • 标签

  • 搜索

188. Best Time to Buy and Sell Stock IV

发表于 2017-08-26 | 分类于 LeetCode | 阅读次数
字数统计 1,837 | 阅读时长 8

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 at most k transactions.

Note:
You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

阅读全文 »

187. Repeated DNA Sequences

发表于 2017-08-26 | 分类于 LeetCode | 阅读次数
字数统计 1,248 | 阅读时长 6

All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: “ACGAATTCCG”.When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.

Write a function to find all the 10 - letter - long sequences(substrings) that occur more than once in a DNA molecule.

For example
Given s = “AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT”,
Return:
[“AAAAACCCCC”, “CCCCCAAAAA”].

阅读全文 »

179. Largest Number

发表于 2017-08-26 | 分类于 LeetCode | 阅读次数
字数统计 394 | 阅读时长 2

Given a list of non negative integers, arrange them such that they form the largest number.
For example, given[3, 30, 34, 5, 9], the largest formed number is 9534330.
Note : The result may be very large, so you need to return a string instead of an integer.

阅读全文 »

173. Binary Search Tree Iterator

发表于 2017-08-26 | 分类于 LeetCode | 阅读次数
字数统计 347 | 阅读时长 2

Implement an iterator over a binary search tree(BST).Your iterator will be initialized with the root node of a BST.
Calling next() will return the next smallest number in the BST.

Note: next() and hasNext() should run in average O(1) time and uses O(h) memory, where h is the height of the tree.

阅读全文 »

166. Fraction to Recurring Decimal

发表于 2017-08-26 | 分类于 LeetCode | 阅读次数
字数统计 1,636 | 阅读时长 7

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.

If the fractional part is repeating, enclose the repeating part in parentheses.

For example,
Given numerator = 1, denominator = 2, return “0.5”.
Given numerator = 2, denominator = 1, return “2”.
Given numerator = 2, denominator = 3, return “0.(6)”.

Hint:
No scary math, just apply elementary math knowledge.Still remember how to perform a long division ?
Try a long division on 4 / 9, the repeating part is obvious.Now try 4 / 333. Do you see a pattern ?
Be wary of edge cases!List out as many test cases as you can think of and test your code thoroughly.

阅读全文 »

164. Maximum Gap

发表于 2017-08-26 | 分类于 LeetCode | 阅读次数
字数统计 947 | 阅读时长 4

Given an unsorted array, find the maximum difference between the successive(相邻的) elements in its sorted form.
Try to solve it in linear time / space.
Return 0 if the array contains less than 2 elements.
You may assume all elements in the array are non - negative integers and fit in the 32 - bit signed integer range.
//如果我们

阅读全文 »

162. Find Peak Element

发表于 2017-08-26 | 分类于 LeetCode | 阅读次数
字数统计 480 | 阅读时长 2

A peak element is an element that is greater than its neighbors.
Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.
The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.

You may imagine that num[-1] = num[n] = -∞.
For example, in array [1, 2, 3, 1], 3 is a peak element and your function should return the index number 2.
Note:
Your solution should be in logarithmic complexity(对数复杂度).

阅读全文 »

160. Intersection of Two Linked Lists

发表于 2017-08-26 | 分类于 LeetCode | 阅读次数
字数统计 744 | 阅读时长 3

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

1
2
3
4
5
6
7
8
9
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.

阅读全文 »

155. Min Stack

发表于 2017-08-25 | 分类于 LeetCode | 阅读次数
字数统计 406 | 阅读时长 2

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.

阅读全文 »

153. Find Minimum in Rotated Sorted Array

发表于 2017-08-24 | 分类于 LeetCode | 阅读次数
字数统计 429 | 阅读时长 2

Suppose a sorted array is rotated at some pivot unknown to you beforehand.

(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Find the minimum element.
You may assume no duplicate exists in the array.

阅读全文 »
1…345…17
CodePikachu

CodePikachu

技术随笔

168 日志
5 分类
7 标签
RSS
GitHub Twitter 微博 知乎
0%
© 2015 - 2020 CodePikachu
博客全站共123.3k字
本站访客数:
由 Hexo 强力驱动
主题 - NexT.Pisces