def test_simple(self): print "TEST test_simple init___________________________" global cList #helper.printList(cList) cr = [] cr.append(creative.Creative(1, "adv1", 100)) cr.append(creative.Creative(2, "adv1", 200, "country")) cr.append(creative.Creative(3, "adv2", 120)) cr.append(creative.Creative(4, "adv2", 100, "country2")) cr.append(creative.Creative(5, "adv2", 100, "country3")) cr.append(creative.Creative(6, "adv3", 50, "country")) cr.append(creative.Creative(7, "adv3", 99)) cr.append(creative.Creative(8, "adv3", 98)) cr.append(creative.Creative(9, "adv4", 80)) cr.append(creative.Creative(10, "adv4", 90)) a = auction.Auction() res = a.perform(cr, 5, "country") helper.printList(res) correct_ids = [2, 3, 7, 10] self.assertTrue(len(res) == 4) x = 0 for i in correct_ids: self.assertEqual(res[x].ID, i) x += 1 print "TEST test_simple end___________________________"
def uiPrintBallaz(l, params): if len(params) != 0: print("Invalid params no!") return if len(l) > 0: printList(l, toStrBalla) return print("Empty list!")
val = val1 + val2 + c if val >= 10: val -= 10 c = 1 else: c = 0 node = ListNode(val) cur.next = node cur = cur.next if l1: l1 = l1.next if l2: l2 = l2.next if c: node = ListNode(c) cur.next = node return dummy.next s = Solution() l1 = LinkedList([9, 9]).head l2 = LinkedList([9]).head l = s.addLists(l1, l2) printList(l) l1 = LinkedList([7, 1, 6]).head l2 = LinkedList([5, 9, 3]).head l = s.addLists(l1, l2) printList(l)
import imp return imp.load_source(name, os.path.join(os.path.dirname(__file__), fpath)) load_src("helper", "../helper.py") from helper import ListNode, LinkedList, printList class Solution: """ @param head: a ListNode @return: a ListNode """ def swapPairs(self, head): # write your code here dummy = ListNode(0, head) cur = dummy while cur and cur.next and cur.next.next: tmp = cur.next cur.next = cur.next.next tmp.next = cur.next.next cur.next.next = tmp cur = cur.next.next return dummy.next s = Solution() head = LinkedList([1, 2, 3, 4]).head printList(s.swapPairs(head))
# write your code here dummy = ListNode(0) dummy.next = head pre = insert_node = dummy while head: if head.val < x: if insert_node.next != head: pre.next = head.next node = insert_node.next insert_node.next = head head.next = node head = pre.next insert_node = insert_node.next else: insert_node = head pre = head head = head.next else: pre = head head = head.next return dummy.next s = Solution() head = LinkedList([1, 4, 3, 2, 5, 2]).head #head = LinkedList([3, 3, 1, 2, 4]).head head = s.partition(head, 3) printList(head) #Input: list = 1->4->3->2->5->2->null, x = 3 #Output: 1->2->2->4->3->5->null