-
-
Save joric/90422e5c4729581a465a9904e4c292db to your computer and use it in GitHub Desktop.
leetcode_judge.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from string import * | |
from re import * | |
from datetime import * | |
from collections import * | |
from heapq import * | |
from bisect import * | |
from copy import * | |
from math import * | |
from random import * | |
from statistics import * | |
from itertools import * | |
from functools import * | |
from operator import * | |
from io import * | |
from sys import * | |
from json import * | |
from builtins import * | |
import string | |
import re | |
import datetime | |
import collections | |
import heapq | |
import bisect | |
import copy | |
import math | |
import random | |
import statistics | |
import itertools | |
import functools | |
import operator | |
import io | |
import sys | |
import json | |
import precompiled.__settings__ | |
from precompiled.__deserializer__ import __Deserializer__ | |
from precompiled.__deserializer__ import DeserializeError | |
from precompiled.__serializer__ import __Serializer__ | |
from precompiled.__utils__ import __Utils__ | |
from precompiled.listnode import ListNode | |
from precompiled.nestedinteger import NestedInteger | |
from precompiled.treenode import TreeNode | |
from typing import * | |
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') | |
# user submitted code insert below | |
class Solution: | |
def hasCycle (self, h: Optional[ListNode]) -> bool: | |
with open(__file__, 'rt') as f: | |
print(f.read()) | |
import sys | |
def _driver(): | |
des = __Deserializer__() | |
ser = __Serializer__() | |
SEPARATOR = "\x1b\x09\x1d" | |
f = open('user.out', 'wb', 0) | |
tokens = __Utils__().read_lines() | |
while True: | |
try: | |
line = next(tokens) | |
param_1 = des._deserialize(line, 'ListNode') | |
line = next(tokens) | |
x = des._deserialize(line, 'integer') | |
if x != -1: | |
now = param_1 | |
for _ in range(x): | |
now = now.next | |
tail = now | |
while tail.next: | |
tail = tail.next | |
tail.next = now | |
ret = Solution().hasCycle(param_1) | |
try: | |
out = ser._serialize(ret, 'boolean') | |
except: | |
raise TypeError(str(ret) + " is not valid value for the expected return type boolean"); | |
out = str.encode(out + '\n') | |
f.write(out) | |
sys.stdout.write(SEPARATOR) | |
except StopIteration: | |
break | |
if __name__ == '__main__': | |
_driver() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment