摘要: Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. Example 1: Example 2: 阅读全文
posted @ 2017-10-25 20:26 daniel456 阅读(220) 评论(0) 推荐(0)
摘要: Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of th 阅读全文
posted @ 2017-10-25 20:23 daniel456 阅读(103) 评论(0) 推荐(0)
摘要: Given a complete binary tree, count the number of nodes. 题目含义:给定一个完整二叉树,求所有节点数 百度百科中完全二叉树的定义如下:若设二叉树的深度为h,除第 h 层外,其它各层 (1~h-1) 的结点数都达到最大个数,第 h 层所有的结点都 阅读全文
posted @ 2017-10-25 20:20 daniel456 阅读(146) 评论(0) 推荐(0)
摘要: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array whic 阅读全文
posted @ 2017-10-25 20:15 daniel456 阅读(428) 评论(0) 推荐(0)
摘要: Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number m 阅读全文
posted @ 2017-10-25 20:09 daniel456 阅读(107) 评论(0) 推荐(0)
摘要: Given 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:Wha 阅读全文
posted @ 2017-10-25 20:05 daniel456 阅读(169) 评论(0) 推荐(0)
摘要: There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every 阅读全文
posted @ 2017-10-25 19:59 daniel456 阅读(118) 评论(0) 推荐(0)
摘要: You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 ston 阅读全文
posted @ 2017-10-25 19:56 daniel456 阅读(114) 评论(0) 推荐(0)
摘要: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. The update(i, val) function modifies nums by upd 阅读全文
posted @ 2017-10-25 19:49 daniel456 阅读(157) 评论(0) 推荐(0)
摘要: Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3].... Example:(1) Given nums = [1, 5, 1, 1, 6, 4], one possible 阅读全文
posted @ 2017-10-25 19:43 daniel456 阅读(131) 评论(0) 推荐(0)
摘要: You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smal 阅读全文
posted @ 2017-10-25 18:58 daniel456 阅读(165) 评论(0) 推荐(0)
摘要: Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. Th 阅读全文
posted @ 2017-10-25 18:55 daniel456 阅读(139) 评论(0) 推荐(0)
摘要: Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed n 阅读全文
posted @ 2017-10-25 18:49 daniel456 阅读(99) 评论(0) 推荐(0)
摘要: You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define a pair (u,v) which consists of one element from th 阅读全文
posted @ 2017-10-25 17:08 daniel456 阅读(103) 评论(0) 推荐(0)
摘要: Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For exam 阅读全文
posted @ 2017-10-25 16:46 daniel456 阅读(95) 评论(0) 推荐(0)
摘要: You are given an integer array sorted in ascending order (may contain duplicates), you need to split them into several subsequences, where each subseq 阅读全文
posted @ 2017-10-25 16:26 daniel456 阅读(180) 评论(0) 推荐(0)
摘要: You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contai 阅读全文
posted @ 2017-10-25 16:10 daniel456 阅读(110) 评论(0) 推荐(0)
摘要: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the 阅读全文
posted @ 2017-10-25 16:07 daniel456 阅读(118) 评论(0) 推荐(0)
摘要: Sort a linked list in O(n log n) time using constant space complexity. 含义:为一个列表排序,要求空间复杂度为常量 思路:使用归并排序 1 public class Solution { 2 public ListNode sor 阅读全文
posted @ 2017-10-25 16:03 daniel456 阅读(92) 评论(0) 推荐(0)
摘要: Sort a linked list using insertion sort. 含义:用插入排序来对列表进行排序 思路:可以构建一个临时的链表,然后将待排序的链表的每一个节点插入到临时链表中 // 插入排序 public ListNode insertionSortList(ListNode he 阅读全文
posted @ 2017-10-25 15:50 daniel456 阅读(87) 评论(0) 推荐(0)
摘要: Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For 阅读全文
posted @ 2017-10-25 15:49 daniel456 阅读(107) 评论(0) 推荐(0)
摘要: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2- 阅读全文
posted @ 2017-10-25 15:39 daniel456 阅读(92) 评论(0) 推荐(0)
摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example,Given 1->2 阅读全文
posted @ 2017-10-25 15:37 daniel456 阅读(112) 评论(0) 推荐(0)
摘要: Given 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 a 阅读全文
posted @ 2017-10-25 15:33 daniel456 阅读(117) 评论(0) 推荐(0)
摘要: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contai 阅读全文
posted @ 2017-10-25 15:31 daniel456 阅读(146) 评论(0) 推荐(0)
摘要: 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 - 阅读全文
posted @ 2017-10-25 15:26 daniel456 阅读(103) 评论(0) 推荐(0)
摘要: Reverse a singly linked list. 含义:翻转一个单列表 类似题目:92. Reverse Linked List II 阅读全文
posted @ 2017-10-25 15:01 daniel456 阅读(102) 评论(0) 推荐(0)
摘要: Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: begin to in 阅读全文
posted @ 2017-10-25 14:34 daniel456 阅读(161) 评论(0) 推荐(0)
摘要: Given 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, 阅读全文
posted @ 2017-10-25 14:26 daniel456 阅读(85) 评论(0) 推荐(0)
摘要: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 含义:合并另个已 阅读全文
posted @ 2017-10-25 14:24 daniel456 阅读(96) 评论(0) 推荐(0)
摘要: The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Now your job is to find the total 阅读全文
posted @ 2017-10-25 12:11 daniel456 阅读(162) 评论(0) 推荐(0)
摘要: Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum result of ai XOR aj, where 0 ≤ i, j < n. Could you do t 阅读全文
posted @ 2017-10-25 12:10 daniel456 阅读(134) 评论(0) 推荐(0)
摘要: Given a positive integer n and you can do operations as follow: What is the minimum number of replacements needed for n to become 1? 含义:给定一个正数n,如果n是偶数 阅读全文
posted @ 2017-10-25 12:05 daniel456 阅读(146) 评论(0) 推荐(0)
摘要: Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assum 阅读全文
posted @ 2017-10-25 11:55 daniel456 阅读(100) 评论(0) 推荐(0)
摘要: Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements 阅读全文
posted @ 2017-10-25 11:44 daniel456 阅读(123) 评论(0) 推荐(0)
摘要: Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive. For example, given the range [5, 阅读全文
posted @ 2017-10-25 11:24 daniel456 阅读(107) 评论(0) 推荐(0)
摘要: Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note:Your algorithm sh 阅读全文
posted @ 2017-10-25 11:12 daniel456 阅读(103) 评论(0) 推荐(0)
摘要: Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Note: Example 1: Exa 阅读全文
posted @ 2017-10-25 11:06 daniel456 阅读(131) 评论(0) 推荐(0)
摘要: The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calcul 阅读全文
posted @ 2017-10-25 11:04 daniel456 阅读(124) 评论(0) 推荐(0)
摘要: Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used. Note: Example 1: Example 2: 阅读全文
posted @ 2017-10-25 11:02 daniel456 阅读(124) 评论(0) 推荐(0)
摘要: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example:Given a = 1 and b = 2, return 3. 含义:不用加减运算符,计算 阅读全文
posted @ 2017-10-25 10:55 daniel456 阅读(93) 评论(0) 推荐(0)
摘要: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Given num = 16, return true. Given num = 5, return fa 阅读全文
posted @ 2017-10-25 10:52 daniel456 阅读(111) 评论(0) 推荐(0)
摘要: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit 阅读全文
posted @ 2017-10-25 10:31 daniel456 阅读(94) 评论(0) 推荐(0)
摘要: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), retur 阅读全文
posted @ 2017-10-25 10:30 daniel456 阅读(94) 评论(0) 推荐(0)
摘要: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another e 阅读全文
posted @ 2017-10-25 10:24 daniel456 阅读(134) 评论(0) 推荐(0)
摘要: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Remov 阅读全文
posted @ 2017-10-25 10:20 daniel456 阅读(160) 评论(0) 推荐(0)