Best Time to Buy and Sell Stock II 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 (i.e., buy one and sell one share of the stock multiple times).Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).Example 1:Input: [7,1,5,3,6,4].. 더보기 Reverse Linked List Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Follow up:A linked list can be reversed either iteratively or recursively. Could you implement both? My Solution:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def reverseList(self, head): """ :type head: ListNode :rtype: L.. 더보기 Remove Nth Node From End of List 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 linked list becomes 1->2->3->5. Note:Given n will always be valid.Follow up:Could you do this in one pass? My solution:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x.. 더보기 이전 1 ··· 5 6 7 8 9 10 11 ··· 53 다음