예제 #1
0
			C = 0

		node = utils.ListNode(val)

		if head is not None:
			tail.next = node
			tail = node
		else:
			head = tail = node

		if p1: p1 = p1.next
		if p2: p2 = p2.next

	return head



h1 = utils.makelist(3, 1, 5)
h2 = utils.makelist(5, 9, 2)
utils.printlist(h1)
utils.printlist(h2)
utils.printlist(sum(h1, h2))


h1 = utils.makelist(1)
h2 = utils.makelist(9, 9, 9)
utils.printlist(h1)
utils.printlist(h2)
utils.printlist(sum(h1, h2))

예제 #2
0
Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.

DEFINITION

Circular linked list: A (corrupt) linked list in which a node’s next pointer points to an earlier node, so as to make a loop in the linked list.

EXAMPLE

Input: A -> B -> C -> D -> E -> C [the same C as earlier]

Output: C
"""

import utils
head = utils.makelist(*"ABCDE")
utils.printlist(head)
head[4].next = head[2]
# utils.printlist(head)


def containsLoop(head):
    if head is None: return False
    sp = fp = head
    while True:
        if fp.next is None or fp.next.next is None:
            return False

        sp = sp.next
        fp = fp.next.next
        if sp == fp:
            return True
예제 #3
0
	while q:
		qsize = len(q)
		head = tail = ListNode(None)
		for i in xrange(qsize):
			treenode = q.popleft()
			node = ListNode(treenode.val)
			tail.next = node
			tail = node

			if treenode.left: q.append(treenode.left)
			if treenode.right: q.append(treenode.right)

		linkedLists.append(head.next)

	return linkedLists




import utils

#   5
#  4  7
# 3   6 8
root = utils.maketree([1, 2, 2, None, 3, None, 3])
utils.printtree(root)
lists = getLevels(root)
for l in lists:
	utils.printlist(l )

예제 #4
0
boolean = True
name = "bread"
nani = """
Rawr x3 nuzzles how are you pounces on you you're so warm 
o3o notices you have a bulge o: someone's happy ;) 
nuzzles your necky wecky~ murr~ hehehe rubbies your bulgy wolgy 
you're so big :oooo rubbies more on your bulgy wolgy it doesn't stop growing 
·///· kisses you and lickies your necky daddy likies (; 
nuzzles wuzzles I hope daddy really likes $: wiggles butt and squirms 
I want to see your big daddy meat~ wiggles butt I have a little 
itch o3o wags tail can you please get my itch~ puts paws on your 
chest nyea~ its a seven inch itch rubs your chest can you help me pwease 
squirms pwetty pwease sad face I need to be punished runs paws down your chest 
and bites lip like I need to be punished really good~ paws on your bulge 
as I lick my lips I'm getting thirsty. I can go for some milk unbuttons 
your pants as my eyes glow you smell so musky :v licks shaft 
mmmm~ so musky drools all over your c**k your daddy meat I like fondles Mr. Fuzzy Balls hehe 
puts snout on balls and inhales deeply oh god im so hard~ licks balls punish me daddy~ nyea~ 
squirms more and wiggles butt I love your musky goodness bites lip please punish me licks lips 
nyea~ suckles on your tip so good licks pre of your c**k salty goodness~ eyes role back and goes 
balls deep mmmm~ moans and suckles
"""
slist = ["cum", "on", "my", "Dump"]
dictionary = {"bread": 1, "milk": 2}

utils.stringprint(nani)
utils.printlist(slist)
utils.dictionarylookup("milk", dictionary)

exit(69)
예제 #5
0
#     def __init__(self, x):
#         self.val = x
#         self.next = None

from utils import ListNode, makelist, printlist


class Solution(object):
	def addTwoNumbers(self, l1, l2):
		"""
		:type l1: ListNode
		:type l2: ListNode
		:rtype: ListNode
		"""
		head = tail = ListNode(None)
		c = 0
		while l1 or l2 or c:
			val = (l1.val if l1 else 0) + (l2.val if l2 else 0) + c
			node = ListNode(val % 10)
			c = val >= 10
			tail.next = node
			tail = node
			if l1: l1 = l1.next
			if l2: l2 = l2.next

		return head.next

l1 = makelist(1,2,3)
l2 = makelist(1,2,7)
printlist(Solution().addTwoNumbers(l1, l2))
예제 #6
0
                if p1:
                    t1.next = p
                    t1 = p
                else:
                    p1 = t1 = p   
            else:
                # append to p2
                if p2:
                    t2.next = p
                    t2 = p
                else:
                    p2 = t2 = p
        
            p = next
        
        if not p1:
            t2.next = None
            return p2
            
        if not p2:
            t1.next = None
            return p1
            
        t1.next = p2
        t2.next = None
        return p1
                        
                
from utils import makelist,printlist
printlist(Solution().partition(makelist(1,1), 2))
예제 #7
0
def main():
    myboard = mainBoard()
    utils.printlist(get_expfiles(subjID='UH_AB_02'))
    myboard.print_Me()
    set_GPIO(myboard.pinmap['SW_FW'], 'IN')
# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    # @param a ListNode
    # @return a ListNode
    def swapPairs(self, head):
        dummy = ListNode(0)
        p = dummy
        
        while head:
            if head.next:
                p.next = head.next
                head.next = head.next.next
                p.next.next = head
                p = head
                head = head.next
                
            else:
                p.next = head
                p = head
                head = head.next
                
        return dummy.next
    
import utils as u
u.printlist(Solution().swapPairs( u.makelist() ))
u.printlist(Solution().swapPairs( u.makelist(1, 2, 3, 4) ))