Coding Rabbit


  • 首页

  • 关于

  • 归档

  • 标签

  • 搜索

List Sort Series

发表于 2016-12-26
Insertion Sort ListQuestionSort a linked list using insertion sort. Analysis An easy and clear way to sort ( O(1) space ) Code1234567891011121314151617181920212223242526272829/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(i ...
阅读全文 »

Reverse Integer || Reverse Bit

发表于 2016-12-23
Reverse IntegerQuestionReverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Analysis越界判断: tmp加上tail后看是否还能变回原来的数字,不可直接利用int型的加和来判断越界(tmp*10+tail>Integer.MAX_VALUE) Code12345678910111213141516171819public class Solution { public int reverse(int x) ...
阅读全文 »

House Robber Series

发表于 2016-12-23
House RobberQuestionYou 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 houses have security system connected and it will automatically contact the police if ...
阅读全文 »

Majority Elements Series

发表于 2016-12-23
Majority ElementQuestionGiven an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element always exist in the array. Analysis Boyer-Moore Majority 直接Array排序后找最多会超时 Code12 ...
阅读全文 »

Course Schedule Series

发表于 2016-12-20
Course ScheduleQuestionThere 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 take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a list of prerequisite pairs, ...
阅读全文 »

Binary Watch || Letter Combinations of a Phone Number

发表于 2016-12-20
Binary WatchQuestionA binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right. For example, the above binary watch reads “3:25”. Given a non-negative ...
阅读全文 »

Trapping Rain Water II || First Missing Positive

发表于 2016-12-19
Trapping Rain Water IIQuestionGiven an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume of water it is able to trap after raining. Note:Both m and n are less than 110. The height of each unit cell is greater than 0 and is less than ...
阅读全文 »

Product of Array Except Self || Trapping Rain Water

发表于 2016-12-17
Product of Array Except SelfQuestionGiven an array of n integers where n > 1, nums, return an array outputsuch that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O(n). For example, given [1,2,3,4], return [24,12,8,6]. Analysis LeetC ...
阅读全文 »

Expression Add Operators || Basic Calculator II

发表于 2016-12-13
Expression Add OperatorsQuestionGiven a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evaluate to the target value. Examples: 12345"123", 6 -> ["1+2+3", "123&quo ...
阅读全文 »

Max Points on a Line || Guess Number Higher or Lower II

发表于 2016-12-12
Max Points on a LineQuestionGiven n points on a 2D plane, find the maximum number of points that lie on the same straight line. Analysis 九章算法 map.put((double)Integer.MIN_VALUE,1); 可能整个序列都是相同点,他们的斜率用MIN_VALUE表示 利用dup变量记录有多少个重复的点 每次进入一个新的坐标点比较的时候记住map.clear 计算key的时候必须+0.0,否则无法通过所有点纵坐标相同的情况 Code1234 ...
阅读全文 »
1…345…8
Coding Rabbit

Coding Rabbit

77 日志
37 标签
RSS
Github Facebook weibo
Links
  • Codeboy
  • Yijia_Jin
© 2017 Coding Rabbit
由 Hexo 强力驱动
主题 - NexT.Mist