- 博客(25)
- 资源 (2)
- 收藏
- 关注
原创 LinkedList
1. 234. Palindrome Linked List 找到中点,反转后面比较 public boolean isPalindrome(ListNode head) { if (head == null) { return true; } ListNode fast = head;
2017-03-29 11:20:41 197
原创 237. Delete Node in a Linked List
1.题目 Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with
2017-03-29 10:33:47 186
原创 leetCode 455 Assign Cookies
1.题目 Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size
2017-03-29 10:19:23 207
原创 452. Minimum Number of Arrows to Burst Balloons
1.题目 原题链接 2.算法 先按坐标的第一个排序,然后按坐标的第二个排序,在用贪心算法, public int findMinArrowShots(int[][] points) { if(points==null || points.length==0) return 0; //优先按照起点位置排序,然后按照结束位置排序 Arrays.sort(points,
2017-03-28 16:49:17 181
原创 Majority Number III
1.题目 给定一个整型数组,找到主元素,它在数组中的出现次数严格大于数组元素个数的1/k。 给出数组 [3,1,2,3,2,3,3,4,4,4] ,和 k = 3,返回 3 2.算法 public int majorityNumber(ArrayList nums, int k) { // write your code HashMap ma
2017-03-28 11:10:45 265
原创 hash function
1.题目 hashcode("abcd") = (ascii(a) * 333 + ascii(b) * 332 + ascii(c) *33 + ascii(d)) % HASH_SIZE = (97* 333 + 98 * 332 + 99 * 33 +100) % HASH_SIZE
2017-03-27 10:53:16 223
原创 Rehashing
1.题目 哈希表容量的大小在一开始是不确定的。如果哈希表存储的元素太多(如超过容量的十分之一),我们应该将哈希表容量扩大一倍,并将所有的哈希值重新安排。假设你有如下一哈希表: size=3, capacity=4 [null, 21, 14, null] ↓ ↓ 9 null ↓ null 哈希函数为: int has
2017-03-27 10:41:35 229
原创 leetCode 174. Dungeon Game
1.题目 原题连接 2.算法 题目的意思是从左上角到右下角,用最少的数值,这道题用动态规划比较好做,我们从反面推,从右下角开始找用最少血的 最先初始化的是公主所在的房间的起始生命值,然后慢慢向第一个房间扩散,不断的得到各个位置的最优的起始生命值。递归方程为: 递归方程是dp[i][j] = max(1, min(dp[i+1][j], dp[i][j+1]) - dungeon[i
2017-03-19 19:45:19 248
转载 leetcode 153: Find Minimum in Rotated Sorted Array
1.题目 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
2017-03-18 21:39:37 198
原创 Search a 2D Matrix II
1.题目 Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right.I
2017-03-16 11:08:25 189
原创 LeetCode 278. First Bad Version
1.题目 You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed base
2017-03-14 11:22:10 210
原创 leetCode 483. Smallest Good Base
1.题目 For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1. Now given a string representing n, you should return the smallest good base of n in string format. The ran
2017-03-13 10:49:26 1009
原创 通过bindservice调用服务内部方法
1.在服务内部定义一个方法 public void banzheng(int money) { if (money < 1000) { Toast.makeText(getApplicationContext(), "太少了", 1).show(); } else if (money > 1000) { Toast.makeText(getApplicationC
2017-03-12 20:30:05 471
原创 android学习笔记(广播接受者)
1.广播接受者步骤 1.定义一个广播接受者 public class OutGoingCallReceiver extends BroadcastReceiver { @Override public void onReceive(Context arg0, Intent arg1) { // TODO Auto-generated method stub String curr
2017-03-12 14:08:41 285
原创 leetCode 166. Fraction to Recurring Decimal
1.题目 Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parenthes
2017-03-10 16:51:09 515
原创 leetcode 313. Super Ugly Number
1.题目 Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 1
2017-03-09 19:59:01 195
原创 leetCode 264. Ugly Number II
1.题目 Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the fi
2017-03-08 09:56:48 172
原创 Java学习笔记泛型
1.泛型类的定义 一个泛型类就是具有一个或多个类型变量的类。 class Pair { private T first; private T second; public T getFirst() { return first; } public void setFirst(T first) { this.first = first; } public T getSeco
2017-03-07 21:02:16 492
原创 Leetcode-263 Ugly Number
1.题目 Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly
2017-03-07 15:21:32 252
原创 leetcode 202. Happy Number
1.题目 Write an algorithm to determine if a number is "happy". 写一个算法,确定一个数字是否是快乐数字,有关快乐数字的定义可以参考百度百科 快乐数字 2.算法 我们从百度百科上发现,不是快乐数的数称为不快乐数(unhappy number),所有不快乐数的数位平方和计算,最後都会进入 4 → 16 → 37 → 58
2017-03-06 09:41:08 577
原创 Leetcode 224: Basic Calculator
1.题目 https://leetcode.com/problems/basic-calculator/?tab=Description 题目的意思是,实现一个基本的计算器来评估一个简单的表达式字符串,字符串可以包括左括号和右括号,加号和减号,不包括非负整数和空格。 2.算法 我们定义一个当前的运算结果res,并定义当前运算结果后的符号digit,当我们遇到(时,res和dig
2017-03-05 10:11:36 385
原创 java总结1
1.编译和运行 javac Student.java //编译 java Student //运行。Student后面不用加。class 2.注释 // 单行注释 /* 我爱你, 我不爱你 */ 多行注释 /** * @author Administrator */ 可以生成文档的注释 3.数据类型 1. 整形 都是有符号的 byte
2017-03-04 10:54:38 190
原创 ListView学习笔记
1.ListView的创建 1.现在xml上面添加一个ListView视图,然后加入id 2.从id中找到Listview然后调用setAdapter(new MyAdapter())创建一个Listview,其中的适配器实现ListAdapter接口 2,优化 适配器中的public View getView(int position, View convertView, ViewG
2017-03-01 20:30:45 192
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人