[스밍] 리허싱.
/**
* Definition for ListNode
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
/**
* @param hashTable: A list of The first node of linked list
* @return: A list of The first node of linked list which have twice size
*/
public ListNode[] rehashing(ListNode[] hashTable) {
// 2015-09-03
if (hashTable == null || hashTable.length == 0) {
return null;
}
int oldSize = hashTable.length;
int newSize = oldSize * 2;
ListNode[] rst = new ListNode[newSize];
for (int i = 0; i < oldSize; i++) {
ListNode curNode = hashTable[i];
while (curNode != null) {
int val = curNode.val;
int newPos = ((val % newSize) + newSize) % newSize; // newPos>0
if (rst[newPos] == null) {
rst[newPos] = new ListNode(val);
} else {
ListNode tail = rst[newPos];
while (tail.next != null) {
tail = tail.next;
}
tail.next = new ListNode(val);
}
curNode = curNode.next;
} // while
} // for
return rst;
}
};
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Jupyter 노트북을 Github에 연결이 게시물은 jupyter 노트북을 github에 연결하는 방법을 탐색하고 개인 참조 역할을 합니다. 이 가이드는 당신이 깃허브 계정이 있고, 깃과 커맨드 라인에 대한 기본 지식이 있고, 현재 주피터 노트북을 사용하...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.