自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(18)
  • 收藏
  • 关注

转载 C++各种变量如何初始化

转载:https://www.cnblogs.com/devilmaycry812839668/p/6357403.html

2021-09-09 23:20:44 243

原创 710. Random Pick with Blacklist 黑名单中的随机数(Hard)

1. 描述给定一个包含 [0,n) 中不重复整数的黑名单 blacklist ,写一个函数从 [0, n) 中返回一个不在 blacklist 中的随机整数。对它进行优化使其尽量少的调用Math.random()。You are given an integer n and an array of unique integers blacklist. Design an algorithm to pick a random integer in the range [0, n - 1] tha

2021-08-29 11:06:54 157

原创 由重写equals()就要重写hashCode()引发的思考

1. equals()和hashCode()的关系equals( ):equals()在java中默认比较地址,是Object类中的方法,故所有对象子类都继承了此方法。但实际应用中常常重写此方法用于比较对象的内容。hashCode():hashCode是jdk根据对象的地址或者字符串或者数字算出来的int类型的数值。public int hashCode()返回该对象的哈希码值。支持此方法是为了提高哈希表(例如 java.util.Hashtable 提供的哈希表)的性能。既然hashcode为i

2021-08-15 10:10:04 97

原创 380. Insert Delete GetRandom O(1) O(1) 时间插入、删除和获取随机元素(Medium)

1. 描述Implement the RandomizedSet class:RandomizedSet() Initializes the RandomizedSet object.bool insert(int val) Inserts an item val into the set if not present. Returns true if the item was not present, false otherwise.bool remove(int val) Removes a

2021-07-25 14:47:37 84

原创 leetcode 283. Move Zeroes(Easy) 移动零

1. 描述Given an integer array nums, move all 0’s to the end of it while maintaining the relative order of the non-zero elements.Note that you must do this in-place without making a copy of the array.给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。2. 分析

2021-07-22 10:33:29 147

原创 leetcode 27. Remove Element(Easy) 移除元素

1. 描述Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed.Since it is impossible to change the length of the array in some languages, you must instead have the

2021-07-21 18:40:15 130

原创 leetcode 26. Remove Duplicates from Sorted Array(Easy) 删除有序数组中的重复项

1. 描述给你一个有序数组 nums ,请你 原地 删除重复出现的元素,使每个元素 只出现一次 ,返回删除后数组的新长度。不要使用额外的数组空间,你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件下完成2. 分析有序数组,首先想到双指针,本题可以采用快慢指针。由于数组有序,相同元素必定相邻,例子中要求的结果是数组的前一部分变更为不重复的元素,故可以用fast指针遍历数组,若fast指向元素与slow指向元素不相等,则将nums[fast]存储到nums[++slow]即可。3.

2021-07-21 17:35:13 56

原创 leetcode 344. Reverse String(Easy) 反转字符串

1. DescriptionWrite a function that reverses a string. The input string is given as an array of characters s.编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 char[] 的形式给出。不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。你可以假设数组中的所有字符都是 ASCII 码表中的可打印字符。2. Analysis要

2021-07-21 10:50:56 72

原创 leetcode 167. Two Sum II - Input array is sorted(Easy) 两数之和 II - 输入有序数组

1. DescriptionGiven an array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number.Return the indices of the two numbers (1-indexed) as an integer array answer of size 2, w

2021-07-19 22:13:02 79

原创 leetcode 876. Middle of the Linked List(Easy) 链表的中间结点

1. DescriptionGiven a non-empty, singly linked list with head node head, return a middle node of linked list.If there are two middle nodes, return the second middle node.给定一个头结点为 head 的非空单链表,返回链表的中间结点。如果有两个中间结点,则返回第二个中间结点。2. Analysis本题采用双指针法——快慢指针

2021-07-19 21:15:59 80

原创 leetcode 141. Linked List Cycle(Easy)

1. DescriptionGiven head, the head of a linked list, determine if the linked list has a cycle in it.There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, po

2021-07-19 20:46:00 64

原创 leetcode 234. Palindrome Linked List(Easy) 回文链表

1. DescriptionGiven the head of a singly linked list, return true if it is a palindrome.Follow up: Could you do it in O(n) time and O(1) space?请判断一个链表是否为回文链表。2. Analysis链表不好判断回文的原因是链表指针的单向性,无法获得前驱结点。故本题第一反应将链表整个反转后与原链表进行比较,但此方法产生了一条与原链表长度相等的新链表,不满足O

2021-07-16 16:35:06 119

原创 leetcode 25. Reverse Nodes in k-Group(Hard)

1. DescriptionGiven a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out

2021-07-15 16:18:36 122

原创 leetecode92. Reverse Linked List II(Medium)

1. DescriptionGiven the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.给你单链表的头指针 head 和两个整数 left 和 right ,其中 left <=

2021-07-15 10:10:52 77

原创 leetcode19. Remove Nth Node From End of List(Medium)

1. DescriptionGiven the head of a linked list, remove the nth node from the end of the list and return its head.给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点。Follow up: Could you do this in one pass?2. Analysis删除倒数第n个节点有些麻烦,自然想到删除正数第n个节点较为简单,故可以反转链表后删除第n个节点再反转链

2021-07-12 22:29:52 67

原创 leetcode 1 Two Sum(Easy)

1. DescriptionGiven an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.You may assume that each input would have exactly one solution, and you may not use the same element twice.You can ret

2021-07-11 09:29:34 54

原创 leetcode 445 Add Two Numbers II(Medium)

1. DescriptionYou are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.You may assume

2021-07-10 13:01:14 80

原创 lt 24 Swap Nodes in Pairs(Medium)

lt24 Swap Nodes in Pairs(Medium)1. DescriptionGiven a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list’s nodes (i.e., only nodes themselves may be changed.)给定一个链表,两两交换其中相

2021-07-08 13:45:36 54

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除