Coding Rabbit


  • 首页

  • 关于

  • 归档

  • 标签

  • 搜索

Fraction to Recurring Decimal || 3Sum Closest

发表于 2016-09-20
Fraction to Recurring DecimalQuestionGiven 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 parentheses. For example, Given numerator = 1, denominator = 2, return “0.5”.Give ...
阅读全文 »

Range Sum Query - Immutable || Range Sum Query 2D - Immutable

发表于 2016-09-19
Range Sum Query - ImmutableQuestionGiven an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: 1234Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRange(0, 5) -> -3 Note:You may assume that the array does not cha ...
阅读全文 »

Remove Duplicates from Sorted List || Remove Duplicates from Sorted List II

发表于 2016-09-18
Remove Duplicates from Sorted ListQuestionGiven a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. Analysis 在头节点前加result用以保存原本的头节点 将current指针指到存在重复值的最后一个节点,且在循环过程中 ...
阅读全文 »

Swap Nodes in Pairs || Palindrome Partitioning II

发表于 2016-09-17
Swap Nodes in PairsQuestionGiven a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can ...
阅读全文 »

Palindrome Linked List || Valid Palindrome || Palindrome Partitioning

发表于 2016-09-13
Palindrome Linked ListQuestionGiven a singly linked list, determine if it is a palindrome. Analysis判断一个链表是否为回文数 判断链表节点个数是奇数还是偶数 偶数的情况下,两个指针,p1一次走一步,并将路过的元素都压栈,p2一次走两步,当p2为null时,p1刚好指向链表中点,此时p1接着向下,元素与依次弹栈的元素进行对比,假如不等,则返回false,否则返回true 奇数的情况下,先将p2先后挪一位,其余相同 Code1234567891011121314151617181920212223 ...
阅读全文 »

Longest Substring Without Repeating Characters || Longest Palindromic Substring

发表于 2016-09-09
Longest Substring Without Repeating CharactersQuestionGiven a string, find the length of the longest substring without repeating characters. Examples: Given “abcabcbb”, the answer is “abc”, which the length is 3. Given “bbbbb”, the answer is “b”, with the length of 1. Given “pwwkew”, the answer is “ ...
阅读全文 »

ZigZag Conversion || Roman to Integer || Longest Common Prefix

发表于 2016-09-08
ZigZag ConversionQuestion The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) 123456> P A H N>> A P L S I I G>> Y I R`> > And then read line by li ...
阅读全文 »

Two Sum || 3 Sum

发表于 2016-09-06
Two SumQuestion Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1]. Tips 第二个脚标 ...
阅读全文 »

Add Binary || Add Two Numbers

发表于 2016-09-05
Add BinaryQuestionGiven two binary strings, return their sum (also a binary string). For example,a = “11”b = “1”Return “100”. Analysis加数的过程是从最低位开始加,假如两个数字位数不同的话高位以0补齐。首先在其中一个数字为0的情况下返回另外一个数字。在经过所有的判断之后,两个指向最高位的游标同时像低位扫描,判断为0/1,同时给temp赋值,取得两个temp与flag的和后判断是否需要进位。在全部扫描过后再看flag是否为1,决定是否需要在加1位。stringbui ...
阅读全文 »

Reverse Linked List

发表于 2016-09-03
非递归(迭代)Analysis由于链表不具有数组可以根据下标随机访问的特性,所以只能从头节点开始逐个的交换到最后一个节点,并且在每次交换过程中需要用两个变量:previous来保存原本处于current节点的前一个节点,previous在交换过程中变为current.next。除此之外,循环的条件是在current不为空的时候,当其为空时,它的previous是新的head。需记住将原头结点的后继设为空。 Code12345678910111213141516171819202122/** * Definition for singly-linked list. * public class ...
阅读全文 »
1…678
Coding Rabbit

Coding Rabbit

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