![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
青菜白玉
怀揣着迷茫,行走在编程的路上的大学狗,编程即世界
展开
-
leetcode-121. Best Time to Buy and Sell Stock
问题描述假设给定一个数组,第i个元素表示第i天股票的价格。假如只允许您完成一笔交易(买和卖),则设计出一种算法找到最大利润。注意不能在买之前就卖了。Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one原创 2020-07-21 00:16:12 · 121 阅读 · 0 评论 -
leetcode-448. Find All Numbers Disappeared in an Array
description给一个元素>=1,<=数组长度的数组,有些元素出现了两次,而其他元素则出现一次,找出在[1,n]范围内的不出现在数组中的元素。要求是最好在O(1)的空间里完成。思路这题,我想了几分钟,发现想不出来,看了讨论区,发现他们的做法好巧妙,觉得这道题考验眼力,[1, n],每个元素都减1后,就成了数组的下标。通过这个做法就可以找出不存在于数组的元素。代码/** * @param {number[]} nums * @return {number[]} */var原创 2020-07-20 00:17:38 · 101 阅读 · 0 评论 -
leetcode-169.Majority Element
description给定一个大小为n的数组,找出数组中元素个数最多(大于n/2)的元素,假定这个元素一定存在且数组非空。思路用一个数组来装元素的个数,用元素本身作为下标代码/** * @param {number[]} nums * @return {number} */var majorityElement = function(nums) { const n = parseInt(nums.length / 2); const eleCount = []; l原创 2020-07-18 08:52:47 · 89 阅读 · 0 评论 -
leetcode-删除链表元素
203. Remove Linked List ElementsRemove all elements from a linked list of integers that have value val.去掉链表中的val。代码class Solution { public ListNode removeElements(ListNode head, int val) { ...原创 2019-10-05 10:48:01 · 131 阅读 · 0 评论 -
leetcode-反向链表
206. Reverse Linked ListReverse a singly linked list.Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLMy codestruct ListNode* reverseList(struct ListNode* head){...原创 2019-08-15 14:59:59 · 129 阅读 · 0 评论 -
leetcode-合并两个排序链表
21. Merge Two Sorted ListsMerge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, ...原创 2019-08-20 16:07:19 · 106 阅读 · 0 评论 -
leetcode- DI字符串匹配
942. DI String MatchGiven a string S that only contains “I” (increase) or “D” (decrease), let N = S.length.Return any permutation A of [0, 1, …, N] such that for all i = 0, …, N-1:If S[i] == “I”, ...原创 2019-07-29 17:18:55 · 111 阅读 · 0 评论 -
leetcode
1 两个求和:给定一个整数数组,返回两个数字的索引,使它们相加到特定目标。您可以假设每个输入只有一个解决方案,并且您可能不会两次使用相同的元素。例:给定nums = [2,7,11,15],target = 9,因为nums [ 0 ] + nums [ 1 ] = 2 + 7 = 9,返回[ 0,1 ]。我当时想的是这个函数里变量都是局部变量,无法返回数...原创 2019-01-28 22:14:45 · 88 阅读 · 0 评论 -
7. 反向整数
Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dea...原创 2019-02-26 23:37:05 · 206 阅读 · 0 评论