leetcode 1. Two Sum

problem

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.


leetcode 242. Valid Anagram

problem

Given two strings s and t , write a function to determine if t is an anagram of s.


哈希表

HashTable & Hash Function & Collisions


HashMap,HashSet,TreeMap,TreeSet

hashtable vs binary-serch-tree

但是二叉搜索树相对有序

leetcode 239. Sliding Window Maximum

题目

Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding window.


leetcode 703. Kth Largest Element in a Stream

Example:

1
2
3
4
5
6
7
8
int k = 3;
int[] arr = [4,5,8,2];
KthLargest kthLargest = new KthLargest(3, arr);
kthLargest.add(3); // returns 4
kthLargest.add(5); // returns 5
kthLargest.add(10); // returns 5
kthLargest.add(9); // returns 8
kthLargest.add(4); // returns 8

leetcode 232. Implement Queue using Stacks

Implement the following operations of a queue using stacks.

push(x) – Push element x to the back of queue.
pop() – Removes the element from in front of queue.
peek() – Get the front element.
empty() – Return whether the queue is empty.


leetcode 20. Valid Parentheses

Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid.

An input string is valid if:

Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Note that an empty string is also considered valid.


堆栈和队列

  1. Stack-先入后出-报纸

  2. Queue-先入先出-队伍

  3. PriorityQueue-优先队列

    • 正常入、按照优先级出
    • 实现机制,堆(二叉堆,多项式堆,斐波那契堆),二叉搜索树s
    • 二叉堆的性能最差,斐波拉契堆效率最好(删除效率为O(logn,其他为 O(1))
    • java,Python中的堆已经实现好了,运用的是斐波拉契堆或者平衡二叉树

leetcode 141. Linked List Cycle

Given a linked list, determine if it has a cycle in it.

To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.


leetcode 24. Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head.

You may not modify the values in the list’s nodes, only nodes itself may be changed.

Example:

1
Given 1->2->3->4, you should return the list as 2->1->4->3.

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×