How does java determine the existence of duplicate elements
I would like to share with you how java judges the existence of repetitive elements. I hope you will gain something after reading this article. Let's discuss it together.
Given an array of integers, determine whether there are duplicate elements.
If any value appears in the array at least twice, the function returns true. Returns false if each element in the array is different.
Example 1:
Input: [1, 2, 2, 3, 1]
Output: true
Example 2:
Input: [1, 2, 3, 4]
Output: false
Example 3:
Input: [1, 1, 1, 1, 3, 3, 4, 3, 4, 3, 4, 4, 4, 2]
Output: true
The problem in the previous issue is: 157, reverse the linked list
1public ListNode reverseList (ListNode head) {
2 if (head = = null | | head.next = = null)
3 return head
4 ListNode tempList = reverseList (head.next)
5 head.next.next = head
6 head.next = null
7 return tempList
8}
Parsing:
List reversal, this is a clich é problem, in fact, there are many ways, let's take a look at two more
1public ListNode reverseList (ListNode head) {
2 ListNode pre = null
3 while (head! = null) {
4 ListNode next = head.next
5 head.next = pre
6 pre = head
7 head = next
8}
9 return pre
10}
eleven
twelve
13public ListNode reverseList (ListNode head) {
14 return reverseListInt (head, null)
15}
sixteen
17private ListNode reverseListInt (ListNode head, ListNode newHead) {
18 if (head = = null)
19 return newHead
20 ListNode next = head.next
21 head.next = newHead
22 return reverseListInt (next, head)
23} after reading this article, I believe you have some understanding of "how java judges the existence of repetitive elements". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!