Українська
Відкрити в Telegram

Постimport java.util.*;

3 липня 2025
D
Deloitte | COGNIZANT | IBM | CAPGEMINI
import java.util.*; public class Main{ public static Node findchain(Node chain1, Node chain2) { int len1 = getLength(chain1); int len2 = getLength(chain2); Node ptr1 = chain1; Node ptr2 = chain2; if (len1 > len2) { int diff = len1 - len2; while (diff-- > 0) ptr1 = ptr1.next; } else { int diff = len2 - len1; while (diff-- > 0) ptr2 = ptr2.next; } while (ptr1 != null && ptr2 != null && ptr1 != ptr2) { ptr1 = ptr1.next; ptr2 = ptr2.next; } Node mergePoint = ptr1; int beforeMerge1 = getDistance(chain1, mergePoint); int beforeMerge2 = getDistance(chain2, mergePoint); Node result = null; if (beforeMerge1 < beforeMerge2 || (beforeMerge1 == beforeMerge2)) { result = cloneUntil(chain1, mergePoint); appendTail(result, mergePoint); } else { result = cloneUntil(chain2, mergePoint); appendTail(result, mergePoint); } return result; } private static int getLength(Node head) { int count = 0; while (head != null) { head = head.next; count++; } return count; } private static int getDistance(Node head, Node stop) { int count = 0; while (head != stop) { head = head.next; count++; } return count; } private static Node cloneUntil(Node head, Node stop) { if (head == stop) return null; Node newHead = new Node(head.value); Node current = newHead; head = head.next; while (head != stop) { current.next = new Node(head.value); current = current.next; head = head.next; } return newHead; } private static void appendTail(Node head, Node tailStart) { if (head == null) return; while (head.next != null) { head = head.next; } head.next = tailStart; } }
1 · 1.7K ·

Поруч у стрічці

DDeloitte | COGNIZANT | IBM | CAPGEMINIJAVA SE8 certification exam ✅✅ 56 Java mcqs✅✅ Contact : @MLCODER2DDeloitte | COGNIZANT | IBM | CAPGEMINICAPITAL ONE✅✅ Contact : @MLCODER2
це повідомлення
DDeloitte | COGNIZANT | IBM | CAPGEMINIDeloitte Communication exam✅✅ Contact : @MLCODER2DDeloitte | COGNIZANT | IBM | CAPGEMINIVIRTUSA PATTERN ✅ 280 Minutes 🥵 Contact: @MLCODER2

Відкрита публічна стрічка з пошукового індексу ChatCrawler — «Google по публічному Telegram»; оновлюється в міру обходу майданчика. Час — UTC.

Лише публічний контент, офіційний API Telegram. Про проєкт · Питання · Межі індексу · Прибрати сторінку з видачі · Каталог · Пошук · Як ми рахуємо