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.
Given nums = [2, 7, 11, 15], target = 9, Because nums + nums = 2 + 7 = 9, return [0, 1].
Continue reading “[Leetcode]1. Two Sum”
Given a non-empty array of integers, every element appears twice except for one. Find that single one.
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Input: [2,2,1] Output: 1
Continue reading “[Leetcode problems]136. Single Number”
Given the array
Continue reading “[Leetcode problems]1475. Final Prices With a Special Discount in a Shop”
prices[i] is the price of the
ith item in a shop. There is a special discount for items in the shop, if you buy the
ith item, then you will receive a discount equivalent to
j is the minimum index such that
j > i and
prices[j] <= prices[i], otherwise, you will not receive any discount at all.
Return an array where the
ith element is the final price you will pay for the
ith item of the shop considering the special discount.
Input: prices = [8,4,6,2,3] Output: [4,2,4,2,3]
Input: prices = [1,2,3,4,5] Output: [1,2,3,4,5]