Given a linked list, check whether it is a palindrome. Examples: Input:   1 -> 2 -> 3 -> 2 -> 1 -> null output: true. Input:   1 -> 2 -> 3 -> null output: false. /** * class ListNode { * public int value; * public ListNode next; *…
http://www.geeksforgeeks.org/function-to-check-if-a-singly-linked-list-is-palindrome/ 这里的reverse可以reverse整个list,这样空间需求就是O(n),不如这个网页写的O(1)的方法 #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <s…
Each of the nodes in the linked list has another pointer pointing to a random node in the list or null. Make a deep copy of the original list. /** * class RandomListNode { * public int value; * public RandomListNode next; * public RandomListNode rand…
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example "Aa" is not considered a palindrome here. Note: Assume the leng…
Total Accepted: 84303 Total Submissions: 302714 Difficulty: Easy Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from t…
78. Subsets Given a set of distinct integers, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example, If nums = [,,], a solution is: [ [], [], [], [,,], [,], [,], [,], [] ] class Solution { public: v…
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Example Given s = "aab", return: [ ["aa","b"], ["a","a","b&q…
1.Type of Tree 1. Binary Tree: a binary tree is a tree in which each node has at most two child nodes(denoted as the left child and the right child). A directed edge refers to the link from the parent to the child (the arrows in the picture of the tr…
2014-03-18 02:57 题目:检查链表是否是回文的,即是否中心对称. 解法:我的做法是将链表从中间对半拆成两条,然后把后半条反转,再与前半条对比.对比完了再将后半条反转了拼回去.这样不涉及额外的空间,比反转整条链表然后比较要来的好.如果你反转了整条链表又不用额外空间,接下来跟谁比去呢? 代码: // 2.7 To Check the given linked list is palindrome or not? #include <cstdio> #include <unord…
10个经典的C语言面试基础算法及代码作者:码农网 – 小峰 原文地址:http://www.codeceo.com/article/10-c-interview-algorithm.html 算法是一个程序和软件的灵魂,作为一名优秀的程序员,只有对一些基础的算法有着全面的掌握,才会在设计程序和编写代码的过程中显得得心应手.本文是近百个C语言算法系列的第二篇,包括了经典的Fibonacci数列.简易计算器.回文检查.质数检查等算法.也许他们能在你的毕业设计或者面试中派上用场. 1.计算Fibona…