Coding Rabbit


  • 首页

  • 关于

  • 归档

  • 标签

  • 搜索

Map && HashSet 操作

发表于 2016-10-11
HashMap与HashSet区别collection框架有自己的接口和实现,主要分为Set接口,List接口和Queue接口。它们有各自的特点,Set的集合里不允许对象有重复的值,List允许有重复,它对集合中的对象进行索引,Queue的工作原理是FCFS算法(First Come, First Serve)。 什么是HashSetHashSet实现了Set接口,它不允许集合中有重复的值,当我们提到HashSet时,第一件事情就是在将对象存储在HashSet之前,要先确保对象重写equals()和hashCode()方法,这样才能比较对象的值是否相等,以确保set中没有储存相等的对象。如果我 ...
阅读全文 »

Group Anagrams || Super Pow

发表于 2016-10-10
Group AnagramsQuestionGiven an array of strings, group anagrams together. For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"],Return: 12345[ ["ate", "eat","tea"], ["nat","tan"], ...
阅读全文 »

Multiply Strings || Excel Sheet Column Title

发表于 2016-10-09
Multiply StringsQuestionGiven two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. Converting the input string to integer is NOT allowed. You should NOT use internal library such as BigInteger. Analys ...
阅读全文 »

Count and Say || Balanced Binary Tree

发表于 2016-10-08
Count and SayQuestionThe 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 “one 2, then one 1” or 1211.Given an integer n, generate the nth sequence. Note: The sequence ...
阅读全文 »

Decode String || Surrounded Regions

发表于 2016-10-06
Decode StringQuestionGiven an encoded string, return it’s decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. You may assume that the input string is always ...
阅读全文 »

Same Tree || Symmetric Tree

发表于 2016-10-05
Same TreeQuestionGiven two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. AnalysisCode123456789101112131415161718/** * Definition for a binary tree node. * public class Tree ...
阅读全文 »

Linked List Random Node || Random Pick Index

发表于 2016-10-03
Linked List Random NodeQuestionGiven a singly linked list, return a random node’s value from the linked list. Each node must have the same probability of being chosen. Follow up:What if the linked list is extremely large and its length is unknown to you? Could you solve this efficiently without usin ...
阅读全文 »

Pascal's Triangle || Pascal's Triangle II

发表于 2016-10-02
Pascal’s TriangleQuestionGiven numRows, generate the first numRows of Pascal’s triangle. For example, given numRows = 5,Return 1234567[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]] Analysis利用pre保存上一行的数据,注意循环边界条件的设定 外层循环,i从2开始,由于第一行是从1开始而非0,即此循环应从第二行开始 内层循环,j从1开始,由于每次是j-1与j相加 Code12345678 ...
阅读全文 »

Sort Colors || Simplify Path

发表于 2016-09-30
Sort ColorsQuestionGiven 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, 1, and 2 to represent the color red, white, and blue respectively. Analysis若是采用遍历 ...
阅读全文 »

Integer to Roman || Integer to English Words

发表于 2016-09-21
Integer to RomanQuestionGiven an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. Analysis罗马数字的构成方法在之前的Roman to Integer整理了 由于数字大小控制在了4000以下,所以可能包含的数字组合情况较少,可以直接用数组进行枚举,能放在左侧且被减去的罗马字母只有X、I、C 贪心策略,每次选取最大的可选数字从num中减去,并且加相应的罗马数字加入字符串中 Code1234567891011 ...
阅读全文 »
1…5678
Coding Rabbit

Coding Rabbit

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