[LeetCode] Pow(x, n)
Pow(x, n) Implement pow(x, n).解题思路:这里n是整数,注意可能是负数,因此需要先将其转化成正数。若直接用循环的方法做,会产生超时错误。我们可以这么做。比如求2^6,我们需要求2^(2*3)=4^3=4*4^2,这样时间复杂度为O(logn)。注意几个特殊的情况,当n==1时,返回x本身,当n==0时,返回1,当n为偶数时,返回myPow(x*x, ...
[LeetCode] Anagrams
AnagramsGiven an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.解题思路:anagrams(变位字)是指对于两个单词来说,长度相同,且构成的字符除了顺序可以不同外,个数都相同。如cinema和iceman就是变位字。判断两...
[LeetCode] Subsets
SubsetsGiven 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 exampl...
[LeetCode] Kth Largest Element in an Array
Kth Largest Element in an ArrayFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given ...
[LeetCode] Combination Sum III
Combination Sum IIIFind all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of ...
[LeetCode] Contains Duplicate
Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false i...
[LeetCode] Rotate Image
Rotate ImageYou 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?解题思路:题目要求原地算法。假设坐标轴如上所示。顺时针旋转90度,...
[LeetCode] House Robber II
House Robber IINote: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much...
程序远表白网,对Ta Say Love
历经两周构思与取材,两天编写代码,程序远表白网V1.0版已经上线啦。网址:http://www.kangry.net/love/。整合了当前网站其他人做的一些模板,修改了一些Bug。目前尚不支持手机版的(手机版样式可能不对)建议用Chorme、Firefox、IE9+等高级浏览器打开。祝你表白成功!插入自定义音乐教程:http://www.kangry.net/blog/?type=article...
如何在程序远表白网中插入自定义音乐?
发现很多人想在程序远表白网(http://www.kangry.net/love/)中自定义背景音乐,但是由于网站空间的限制,我上传的可选音乐非常有限。如果你想自定义背景音乐,可以按照下列教程来做。注:很多朋友贴了虾米、百度、酷我音乐页面的链接,其实是不对滴,要贴出mp3类型的网址路径。下面介绍如何在http://musicase.me/中找到你要的背景音乐链接。这个网址是供海外用户听国内音乐的,...
JS获得当前时间,并格式化
function getNowFormatDate() { var date = new Date(); var year = date.getFullYear(); var month&n...
[LeetCode] Symmetric Tree
Symmetric TreeGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 /&nb...
[LeetCode] Add and Search Word - Data structure design
Add and Search Word - Data structure designDesign a data structure that supports the following two operations:void addWord(word) bool search(word)search(word) can search a literal word or a...
万晓利-女儿情
万晓利版的女儿情,正在练习中。先把谱子记下来。教学视频:万晓利版本:万晓利原版吉他谱:教学版本吉他谱:
[LeetCode] Same Tree
Same TreeGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.解题思路:递归做即...
[LeetCode] Merge Sorted Array
Merge Sorted ArrayGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough spa...
[LeetCode] Course Schedule II
Course Schedule IIThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first ...
溪行桃花源-李志辉
[LeetCode] Maximum Depth of Binary Tree
Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.解题思路:这道题就是求二叉树...
[LeetCode] Binary Tree Level Order Traversal
Binary Tree Level Order TraversalGiven a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {...