- 博客(28)
- 收藏
- 关注
原创 android之sqlite增删改查
public Uri insert(Uri uri, ContentValues values) { SQLiteDatabase db=dBhelper.getWritableDatabase(); long rowid=db.insert("student",null,values); Uri uri2= ContentUris.withAppendedId(uri,r
2015-12-30 22:24:13 377
原创 (java)Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.思路:本题就是一个字符串匹配的问题。本人能想到的有1:暴力穷举法2:kmp算法3:BM算法4:Sunda
2015-12-30 18:21:51 248
原创 (java)Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]思路:就是
2015-12-29 09:52:14 287
原创 (java)Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?思路:本题题意是判断一个链表是否是回文链表,注意本题要求空间复杂度是0(1),所以不能借助其它的容器。先遍历一遍此链表,得到此链表的长度,然后将链表的后半部
2015-12-29 09:46:23 239
原创 (java)Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".思路:就是普通的加法,加入进位就行。注意循环结束的时候,如果进位为1,则在前面加一个1就可代码如下(已通过leetcode)public class S
2015-12-29 09:42:36 373
原创 (java)Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t
2015-12-29 09:35:49 307
原创 (java)Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as
2015-12-29 09:28:06 245
原创 (java)Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5思路:判断p.next.val是否等于val,如
2015-12-29 09:23:48 284
原创 (java)Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.
2015-12-29 09:18:25 280
原创 (java) Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot
2015-12-17 22:15:53 318
原创 (java) Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va
2015-12-17 22:13:13 231
原创 (java)Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the
2015-12-17 22:03:45 194
原创 (java)Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis at most k.思
2015-12-17 19:34:31 259
原创 (java)Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota
2015-12-17 19:29:34 503
原创 (java)Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is
2015-12-17 19:24:25 265
原创 (java)Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille
2015-12-16 12:13:26 242
原创 (java)Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010
2015-12-16 12:10:45 349
原创 (java)Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add
2015-12-16 12:04:54 279
原创 (java)Intersection of Two Linked Lists
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 ↘
2015-12-16 11:58:01 168
原创 (java)Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.思路:也是穷举法的方法,每次都取最小的深度。当root==null时
2015-12-16 11:51:33 217
原创 (java)Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet
2015-12-10 14:37:49 331
原创 (java) Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum
2015-12-10 14:33:23 203
原创 (java)Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].思路:我们可以把这个pascal三角用二维数组来解决。a[i][0]=1,a[i][j]=a[i-1][j-1]+a[i-1][j]根据此递推式就可以得出a[i
2015-12-10 14:27:19 314
原创 (java)Binary Tree Level Order Traversal
Given 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 {3,9,20,#,#,15,7}, 3 / \ 9 20
2015-12-05 17:14:48 215
原创 (java)Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.思路:本题只要判断n!中2和5的个数,min(count(2),count(5))就是阶层之后0的个数n!中count(5)肯定
2015-12-05 17:08:31 318
原创 (java)Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]思路:设置一个int[numRows][numRows]
2015-12-05 17:01:50 346
原创 (java)Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.思路:将n加1,设置一个flag=1 ,
2015-12-05 16:53:27 331
原创 (java)House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house
2015-12-05 16:39:31 317
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人