Given an array of integersnums and an integertarget, returnindices of the two numbers such that they add up totarget.
You may assume that each input would haveexactlyone solution, and you may not use thesameelement twice.
You can return the answer in any order.
Example 1:
Input: nums = [2,7,11,15], target = 9
yoruru 發表在
痞客邦
留言(0)
人氣()
4. Median of Two Sorted Arrays
Given two sorted arraysnums1andnums2of sizemandnrespectively, returnthe medianof the two sorted arrays.
The overall run time complexity should beO(log (m+n)).
Example 1:
Input: nums1 = [1,3], nums2 = [2]
yoruru 發表在
痞客邦
留言(0)
人氣()
215. Kth Largest Element in an Array
Given an integer arraynumsand an integerk, returnthekthlargest element in the array.
Note that it is thekthlargest element in the sorted order, not thekthdistinct element.
You must solve it inO(n)time complexity.
Example 1:
yoruru 發表在
痞客邦
留言(0)
人氣()
75. Sort Colors
Given an arraynumswithnobjects colored red, white, or blue, sort themin-placeso that objects of the same color are adjacent, with the colors in the order red, white, and blue.
We will use the integers0,1, and2to represent the color red, white, and blue, respectively.
You must solve this problem without using the library's sort function.
Example 1:
yoruru 發表在
痞客邦
留言(0)
人氣()
179. Largest Number
Given a list of non-negative integersnums, arrange them such that they form the largest number and return it.
Since the result may be very large, so you need to return a string instead of an integer.
Example 1:
Input: nums = [10,2]
yoruru 發表在
痞客邦
留言(0)
人氣()
27. Remove Element
Given an integer arraynumsand an integerval, remove all occurrences ofvalinnumsin-place. The order of the elements may be changed. Then returnthe number of elements innumswhich are not equal toval.
Consider the number of elements innumswhich are not equal tovalbek, to get accepted, you need to do the following things:
- Change the array
numssuch that the firstkelements ofnumscontain the elements which are not equal toval. The remaining elements ofnumsare not important as well as the size ofnums.
- Return
k.
yoruru 發表在
痞客邦
留言(0)
人氣()
56. Merge Intervals
Given an array ofintervals whereintervals[i] = [starti, endi], merge all overlapping intervals, and returnan array of the non-overlapping intervals that cover all the intervals in the input.
Example 1:
Input: intervals = [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
yoruru 發表在
痞客邦
留言(0)
人氣()
735. Asteroid Collision
We are given an arrayasteroidsof integers representing asteroids in a row.
For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.
Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.
Example 1:
yoruru 發表在
痞客邦
留言(0)
人氣()
1249. Minimum Remove to Make Valid Parentheses
Given a stringsof'(',')'and lowercase English characters.
Your task is to remove the minimum number of parentheses ('('or')', in any positions ) so that the resultingparentheses stringis valid and returnanyvalid string.
Formally, aparentheses stringis valid if and only if:
- It is the empty string, contains only lowercase characters, or
yoruru 發表在
痞客邦
留言(0)
人氣()
1209. Remove All Adjacent Duplicates in String II
You are given a stringsand an integerk, akduplicate removalconsists of choosingkadjacent and equal letters fromsand removing them, causing the left and the right side of the deleted substring to concatenate together.
We repeatedly makekduplicate removalsonsuntil we no longer can.
Returnthe final string after all such duplicate removals have been made. It is guaranteed that the answer isunique.
Example 1:
yoruru 發表在
痞客邦
留言(0)
人氣()
1472. Design Browser History
You have abrowserof one tab where you start on thehomepageand you can visit anotherurl, get back in the history number ofstepsor move forward in the history number ofsteps.
Implement theBrowserHistoryclass:
BrowserHistory(string homepage)Initializes the object with thehomepage of the browser.
void visit(string url) Visits urlfrom the current page. It clears up all the forward history.
yoruru 發表在
痞客邦
留言(0)
人氣()
20. Valid Parentheses
Given a stringscontaining just the characters'(',')','{','}','['and']', determine if the input string is valid.
An input string is valid if:
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
yoruru 發表在
痞客邦
留言(0)
人氣()