给定一个整数数组和一个目标值,找出数组中和为目标值的两个数。 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用。 示例: 给定 nums = [2, 7, 11, 15], target = 9 因为 num…
分类:LeetCode
数组中的第K个最大元素
在未排序的数组中找到第 k 个最大的元素。请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素。 输入: [3,2,1,5,6,4] 和 k = 2 输出: 5 输入: [3,2,3,1,2,…
Leetcode 93.Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations. For…
LeetCode[6] - Count Primes
方法很牛逼也很数学。没做的时候可能想不到。做了之后就觉得,哎,我去,有道理啊。 简而言之:简历一个boolean长条,存isPrime[]。 然后从i=2, 全部变true. 然后利用这个因子的性质,非prime满足条件…
LeetCode刷题之Climbing Stairs
Problem You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 …
[LeetCode By Go 84]66. Plus One
题目 Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may a…
90. Subsets II
90. Subsets II 题目 Given a collection of integers that might contain duplicates, nums, return all possible subs…
LeetCode | Swap Nodes in Pairs(将链表中的元素两两交换)
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3-…
[LintCode][System Design] Web Logger
Problem More Discussions Implement a web logger, which provide two methods: hit(timestamp), record a hit at gi…
[LeetCode] Flatten Binary Tree to Linked List 将二叉树展开成链表
Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 &nbs…
[LeetCode] Shortest Word Distance 最短单词距离
Given a list of words and two words word1 and word2, return the shortest distance betwee…
LeetCode | Jump Game
题目: Given an array of non-negative integers, you are initially positioned at the first index of the array. Eac…