Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. 题目要求 : 求整数数组的所有子集 注意: 1.子集元素按非降序排列 2.不包含重复的子集 解题思路: 求解这类诸如子集的题目,都可以采用回溯…
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word: a) Insert a characterb) Delete a characterc) Replace…
题目 Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, If nums = [1,2,3], a solution is: [ [3], [1], [2], […
================================== LeetCode的一些算法题,都是自己做的,欢迎提出改进~~ LeetCode:http://oj.leetcode.com ================================== <Reverse Words in a String>-20140328 Given an input string, reverse the string word by word. For example, Given s =…
326. Power of ThreeGiven an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion? 看到这种题目,第一想法就是用递归或者循环来做,但是题目要求了不能用这种方法来做,所以只能另想他法. 假设输入一个数 n,如果 n 是3的幂,那么 3^x = n, 即 x = log10…
Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and uses constant space. 题目: 给一无序数组,找到数组中从1开始第一个不出现的正整数. 要求O(n)的时间复杂度和常数空间复杂度…
Suppose a sorted array 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). Find the minimum element. You may assume no duplicate exists in the array. 题目: 给定一旋转有序数组,求该数组的最小值. 思路: 二分查找Binary Search 比较简单…
Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1 → b2 → b3 begin to intersect at node c1. Notes: If the two linked lists have…