随笔分类 -  算法

摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: 阅读全文
posted @ 2019-01-25 11:17 米开朗菠萝 阅读(131) 评论(0) 推荐(0)
摘要:# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def partition(self, head, x):... 阅读全文
posted @ 2019-01-15 19:04 米开朗菠萝 阅读(84) 评论(0) 推荐(0)
摘要:#!/usr/bin/python # -*- coding: UTF-8 -*- from pythonds.basic.stack import Stack def parChecker(symbolString): s = Stack() balanced = True index = 0 w 阅读全文
posted @ 2018-12-13 23:14 米开朗菠萝 阅读(1220) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1: Input: 1->1->2 Output: 1->2 Example 2: Input: 1- 阅读全文
posted @ 2018-11-29 12:22 米开朗菠萝 阅读(102) 评论(0) 推荐(0)
摘要:由于题目说了有且只有唯一解,可以考虑两遍扫描求解:第一遍扫描原数组,将所有的数重新存放到一个dict中,该dict以原数组中的值为键,原数组中的下标为值;第二遍扫描原数组,对于每个数nums[i]查看target-nums[i]是否在dict中,若在则可得到结果。 当然,上面两遍扫描是不必要的,一遍 阅读全文
posted @ 2018-06-01 14:02 米开朗菠萝 阅读(146) 评论(0) 推荐(0)
摘要:python版本: 阅读全文
posted @ 2016-05-25 21:43 米开朗菠萝 阅读(423) 评论(0) 推荐(0)