-
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array return its index, otherwise return -1. You may assume no duplicate exists in the array. 思路:找规律。。。二分。。。 0 1 2 3 4 …
Read More -
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found in the array, return [-1, -1]. For example, Given [5, 7, 7, 8, 8, 10] and target value 8, return [3, 4]. 思 …
Read More -
Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited number of times. Note: * All numbers (including target) will be positive integers. * The solution set must …
Read More -
* Total Accepted: **106670** * Total Submissions: **329718** * Difficulty: **Medium** * Contributor: **LeetCode** Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in the combination. …
Read More -
In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo's attacking ascending time series towards Ashe and the poisoning time duration per Teemo's attacking, you need to output the total time that Ashe is in poisoned condition. You may assume …
Read More -
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twice in this array. Could you do it without extra space and in O(n) runtime? 思路:还是一个映射,如果某个位置要映射的时候已经为负了,就说明之前映射过该位置,那么该位置对应的元素就是出现了两个的元素。 和leetcode 448是一对题目。 /* …
Read More -
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you do this in-place? 题意:给一个n*n的方阵,要求顺时针旋转90度。 思路:(x,y)->(y,n-1-x); 要求in-place的做法的话,其实是若干长度为4的环,保护一个节点,然后顺次做就好了。 然后对于那些标记已经做过选旋转的问题,实际上没有必要进行标记。 对于偶数,只需要处理 左上角hf * hf个,奇数只需要处理左上角hf*(hf-1)个。 其中hf = …
Read More -
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. 思路:。。。再次让我回想起高一的暑假。。。。 /* *********************************************** Author :111qqz Created Time :2017年04月11日 星期二 19时42分05秒 File Name :54.cpp ************************************************ */ class Solution { …
Read More -
Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. 思路:dp[i]表示能否到达位置i...无脑dp即可。。。 /* *********************************************** Author :111qqz Created Time :2017年04月11日 星期二 19时33分51秒 File Name :55.cpp …
Read More -
Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. 思路:扫一遍即可。。 /* *********************************************** Author :111qqz Created Time :2017年04月11日 星期二 19时15分30秒 File Name :56.cpp …
Read More