- 博客(14)
- 收藏
- 关注
原创 116.Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = "hello", return "holle". Example 2: Given s = "leetcode", return "leotcede".
2016-04-23 23:26:55 487
原创 115.Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 分析:采用递归的思想。首先找到根结点,再找到左子树的根结点和右子树的根结点。 /** * Given an array where elements are sorted in ascending
2016-04-23 11:06:38 244
原创 114.Reverse String
Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". 分析: 首先把字符串转化为字符数组,然后转置字符数组,然后再转化为字符串。不直接交换字符串是因为字符串是不可变的,每次改变字符串
2016-04-23 10:12:12 196
原创 113.Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Given num = 16, return true. Given num = 5, return false. Follow up: Could you solve it without
2016-04-21 11:33:13 248
原创 112.Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example, Given n = 3, You should return the following matrix: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [
2016-04-17 09:00:23 212
原创 111.Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node.
2016-04-17 08:51:38 194
原创 110.Find Minimum in Rotated Sorted Array
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
2016-04-17 08:21:18 210
原创 109.Two Sum
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. Example: Given nums =
2016-04-16 22:08:27 288
原创 Java中list、set、map的输出格式
Java中的集合主要有list、set、map三种。其输出格式也不全相同,直接输出这个集合对象,测试代码个输出如下所示。 import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; public class Test { public static void main(String[] ar
2016-04-12 22:32:56 18290
原创 Java中的取模运算
在Java中取模运算的结果是被除数除以除数的余数,但是如果除数或被除数有一个是负数或者两个都是负数的时候由会怎么计算呢?先来看一个例子: public static void main(String[] args){ int dividend = -1;//被除数 int divisor = 2;//除数 System.out.println(dividend % divisor);
2016-04-11 22:32:10 3253
原创 108.Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements. Follow up: What if the
2016-04-10 10:27:37 238
原创 107.Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: Given nums = [-2, 0, 3, -5, 2, -1] sumRange(0, 2) -> 1 sumRange(2, 5) -> -1 sumRan
2016-04-10 09:59:01 194
原创 106.Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array. Example: For num = 5
2016-04-05 10:00:49 186
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人