1 pass solution 就是一边扫描数组, 一边更新Map。 如果找到满足要求的pair, 直接返回, 否则把当前的数插入到Map中. 1publicclassSolution {2publicint[] twoSum(int[] nums,inttarget) {3Map<Integer, Integer> map =newHashMap<Integer, Integer>();4for(inti = 0; i < nums.length; i++) {5if(m...
1/**2* Created by sheepcore on 2019-05-073*/4classSolution {5publicint[] dailyTemperatures(int[] T) {6int[] res =newint[T.length];7for(inti = 0; i < T.length -1; i++){8booleanhasWarmerDay =false;9for(intj = i + 1; j < T.length; j++){10if(T[i] <T[j]){11res...
private String envInfo; private String dailyRecordStatus; private String style; private String __typename; private List<TopicTagsBean> topicTags; private List<CodeSnippetsBean> codeSnippets; @Data public static class SolutionBean { private String id; private boolean canSeeDetail; private String __typ...
89. Gray Code 已做到时间+空间最优解,运算全部位运算,不论golang还是C++都做不到0ms解或则最优空间解。147. Insertion Sort List 要求在单链表上实现插入排序(时间复杂度:O(n^2),空间:O(1)),但为了在线评测中时间表现优异,添加了快速排序实现(时间复杂度:O(nlog(n)),空间:O(n))。
class Solution(object): def dailyTemperatures(self, temperatures): """ :type temperatures: List[int] :rtype: List[int] """ n = len(temperatures) ans = [0]*n stack = [0] for i in range(1,n): if temperatures[i]<=temperatures[stack[-1]]: stack.append(i) else: while stack and...
Welcome to follow my subscription account on Wechat, I will update the newest updated problem solution and explanation. And also welcome to add me as your wechat friend. iOS APP - Leetcode Meet Me This app displays all practical coding problems from leetcode.com, and provids the solutions....
No registration is required. To join, just start solving the daily problem on the calendar of theproblem page. You can also find the daily problem listed on the top of theproblem page. The daily problem will be updated onevery 12 a.m. Coordinated Universal Time (UTC)and you will have ...
class Solution { public int[] dailyTemperatures(int[] temperatures) { LinkedList<int[]> stack = new LinkedList<>(); int len = temperatures.length, i=1; int []res=new int[len]; stack.addLast(new int[]{temperatures[0], 0}); while (!stack.isEmpty()){ while (!stack.isEmpty() &&...
you need to carefully read the description of the task, look at the examples that we are given (input) and what we need to get (output), submit the problem and understand that there is such a thing as edge cases, when your solution covers 3 examples that you were given, but the rema...
218 The Skyline Problem Solution O(n) O(n) Hard TreeMap, Design 219 Contains Duplicate II Solution O(n) O(n) Easy HashMap 220 Contains Duplicate III Solution O(nlogn) O(n) Medium TreeSet 221 Maximal Square Solution O(?) O(h) Medium Recursion 222 Count Complete Tree Nodes Solution ...