recursion

Recursive palindrome check with JavaScript

喜你入骨 提交于 2020-08-27 21:33:25
问题 I am trying to find out whether a string is a palindrome by recursion using javascript. But I can't figure out what I am missing in the code. var firstCharacter = function(str) { return str.slice(0, 1); }; var lastCharacter = function(str) { return str.slice(-1); }; var middleCharacters = function(str) { return str.slice(1, -1); }; var isPalindrome = function(str) { if(str.length < 2) { return true; } else { if(firstCharacter(str) == lastCharacter(str)) { isPalindrome(middleCharacters(str));

Recursively iterate through a nested dict with list, and replace matched values

蹲街弑〆低调 提交于 2020-08-26 04:42:26
问题 I want to make a function that iterate through a nested dict that include list. For each value that match with a keyword, the function replace it with another keyword. It's not important if the function return another dict or if it change the main dict. I tried to separate the case: - if the data is a dict, make something - if the data is a list, make something else DICT: data_dict = { "name": "AAAAAA", "content": "BBBBBB", "dat": [ { "author": { "name": "CCCCCC", "surname": "DDDDDD", },

Making a deep copy of a LinkedList in java

萝らか妹 提交于 2020-08-24 03:45:09
问题 I have a Linked List and I'm trying to create a copy of another Linked List and this copy is a deep copy because the element type is char. Due to the complexity of linked lists, I've tried not to use the add method. My code is shown below. Also I want to recursively add all the elements from some list to my original list but the problem with my implementation is that it only adds the first element in the list and not all of it. Why is this so? public class CharLinkedList { private static

How Recursion Works Inside a For Loop

爷,独闯天下 提交于 2020-08-21 05:20:41
问题 I am new to recursion and trying to understand this code snippet. I'm studying for an exam, and this is a "reviewer" I found from Standford' CIS Education Library (From Binary Trees by Nick Parlante). I understand the concept, but when we're recursing INSIDE THE LOOP, it all blows! Please help me. Thank you. countTrees() Solution (C/C++) /* For the key values 1...numKeys, how many structurally unique binary search trees are possible that store those keys. Strategy: consider that each value

How Recursion Works Inside a For Loop

梦想的初衷 提交于 2020-08-21 05:19:58
问题 I am new to recursion and trying to understand this code snippet. I'm studying for an exam, and this is a "reviewer" I found from Standford' CIS Education Library (From Binary Trees by Nick Parlante). I understand the concept, but when we're recursing INSIDE THE LOOP, it all blows! Please help me. Thank you. countTrees() Solution (C/C++) /* For the key values 1...numKeys, how many structurally unique binary search trees are possible that store those keys. Strategy: consider that each value