Given an array [a1b2c3d4] convert to [abcd1234] with 0(1) space and O(n) time
来源:互联网 发布:linux内核设计与实现 编辑:程序博客网 时间:2024/06/07 10:43
http://learn.hackerearth.com/forum/134/there-is-a-string-like-abcde12345-convert-it-in-form-of/
从 a1b2c3d4 --> abcd1234
voidconvertArray(char* array, intlength) {
inti;
if(length >=4) {
convertArray(array, length/2);
convertArray(array + length/2, length/2);
for(i=0; i<length/4; i++) {
swap(array+(length/2)/2+i, array+(length/2)+i);
}
}
}
从abcd1234 --> a1b2c3d4 是上面过程的反过程
void fun(char s[], int n) { // Base case if(n == 2) return; else { swap_str(s+n/4, s+n/2, n/4); fun(s, n/2); fun(s + n/2, n/2); } }void swap_str(char s1[], char s2[], int n){ for(int i = 0; i < n; i++) swap(s1[i], s2[i]);}
0 0
- Given an array [a1b2c3d4] convert to [abcd1234] with 0(1) space and O(n) time
- separate odd and even numbers in an array in O(n) time complexity and O(1) space complexity
- Best Time to Buy and Sell Stock Short python solution, O(n) runtime, O(1) space
- Find duplicates in O(n) time and O(1) extra space
- LeetCode234——Palindrome Linked List,O(n) time and O(1) space
- Given an infinite size array with only 0s and 1s and sorted. find the transition point where 0s end
- 27. Given an array and a value
- Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missi
- Given an array of size N in which every number is between 1 and N, determine if there are any dupli
- Give an O(lg n)-time algorithm to find the median of all 2n elements in arrays X and Y.
- Given a roman numeral, convert it to an integer.
- Solution to Maximum Subarray in linear-time algorithm with time complexity is O(n)
- You’re given an array containing both positive and negative integers and required to find the sub-a
- 9. 11. 30. 从asList到toArray转换 -Convert a List (ArrayList) to an Array with zero length array
- Select n numbers from 1 to m with all of array 'all' and none of array 'none'
- Edit Distance (O(n^2) and O(n) space)
- java convert timestamp to date and time
- How to call different methods as given in an array
- TCP状态转换图及TIME_WAIT状态
- HDU2109 Fighting for HDU【水题】
- kafka queue full解决办法
- 《算法导论》笔记:第1章
- C#面向对象第五天总结
- Given an array [a1b2c3d4] convert to [abcd1234] with 0(1) space and O(n) time
- oracle 序列
- 《算法导论》笔记:第2章
- SharePoint 2010中的沙盒解决方案(Sandboxed Solution)
- 信息系统项目管理师:项目经理的一般要求
- 图解数据结构之总纲
- 使用流(Working with Streams)
- 【BZOJ 1271】 [BeiJingWc2008]秦腾与教学评估
- 微软或将对外推出付费版Cosmos大数据服务