- 博客(17)
- 资源 (25)
- 收藏
- 关注
原创 翻转子串
题目描述给定两个字符串s1,s2,请返回bool值代表s2是否由s1旋转而成。字符串中字符为英文字母和空格,区分大小写解析:通过旋转一个字串即可 public boolean checkReverseEqual(String s1, String s2) { //安全性检查 if(s1==null||s2==null) return false; String t
2015-07-31 22:45:39 789
原创 清除行列
题目描述请编写一个算法,若MxN矩阵中某个元素为0,则将其所在的行与列清零。思路:为行列各自建立一个boolean数组,先用双重循环遍历将0对应的位置填上true,然后再双重循环一遍,结合行列boolean数组将对应的位置填写0即可 public int[][] clearZero(int[][] mat, int n) { // 遍历一遍将0的元素行列标记为true bo
2015-07-31 22:06:08 1458
原创 像素翻转
题目描述有一副由NxN矩阵表示的图像,这里每个像素用一个int表示,请编写一个算法,在不占用额外内存空间的情况下(即不使用缓存矩阵),将图像顺时针旋转90度。给定一个NxN的矩阵,和矩阵的阶数N,请返回旋转后的NxN矩阵,保证N小于等于500,图像元素小于等于256。测试样例:[[1,2,3],[4,5,6],[7,8,9]],3返回:[[7,4,1],[8,5,2],[9,6
2015-07-31 21:21:40 770
原创 String to Integer (atoi)
Implement atoi to convert a string to an integer.题目解析:atoi函数 把字符串转为整型思路解析:主要是考虑各种输入的 +123,-123 ,123, 123(空格),算是个比较简单的题目,直接上AC代码 public int myAtoi(String str) { // 安全性检查 if (str.lengt
2015-07-29 22:53:50 931
原创 Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.题目解析:找出一个匹配子串的位置所在思路一:普通解法,记录位置双重循环public int strStr(String hays
2015-07-29 22:50:10 690
原创 Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using
2015-07-29 22:42:57 649
原创 Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.题目解析:二叉树的前序遍历思路 递归ok,下面至直接上AC代码/** * Definition for a binary tree node. * public class TreeNode { * int val; *
2015-07-29 22:32:29 479
原创 Rotate Array
For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to[5,6,7,1,2,3,4]. 题目解析:旋转数组思路:双重循环,需要记录每次开始的数,然后移动数组,最后将首位数组互换即可,还是比较简单的,下面是AC代码public void rotate(int[] nums, int k) {
2015-07-29 22:28:06 829
原创 Sort List
Sort a linked list in O(n log n) time using constant space complexity.题目分析:给一个链表排序,这玩意有点不好弄思路解析: 本题先将链表拆成俩个 (拆后要将俩个链表恢复成正常),递归的将俩个字链表排序, 最后将结果合并,思路简单但是操作起来不好弄,直接上AC代码/** * Definition for singl
2015-07-29 22:10:47 569
原创 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is9534330.Note: The result may be very
2015-07-29 21:59:27 654
原创 Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0,
2015-07-29 21:40:26 514
原创 Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares o
2015-07-29 21:17:28 535
原创 3Sum
Given an array S of n integers, are there elements a,b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c) m
2015-07-29 21:03:35 517
原创 Word Break
Given a string s and a dictionary of words dict, determine ifs can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet",
2015-07-29 20:41:05 656
原创 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where
2015-07-29 20:24:47 711
viewPager搭框架
2015-11-10
json解析,异步下载(listview仅滑动时加载)Demo
2015-10-10
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人