随笔分类 - 算法
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example:
阅读全文
摘要:# 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):...
阅读全文
摘要:#!/usr/bin/python # -*- coding: UTF-8 -*- from pythonds.basic.stack import Stack def parChecker(symbolString): s = Stack() balanced = True index = 0 w
阅读全文
摘要: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-
阅读全文
摘要:由于题目说了有且只有唯一解,可以考虑两遍扫描求解:第一遍扫描原数组,将所有的数重新存放到一个dict中,该dict以原数组中的值为键,原数组中的下标为值;第二遍扫描原数组,对于每个数nums[i]查看target-nums[i]是否在dict中,若在则可得到结果。 当然,上面两遍扫描是不必要的,一遍
阅读全文
摘要:python版本:
阅读全文

浙公网安备 33010602011771号