development

Rotate an Array using Constant Space

class Solution(object): def reverse(self, start, end, nums): while start < end: nums[start], nums[end] = nums[end], nums[start] start += 1 end -= 1 def rotate(self, nums, k): “”” :type nums: List[int] :type k: int :rtype: None Do not return anything, modify nums in-place instead. “”” if len(nums) == 0: return nums k = k % len(nums) […]

Read more
c language, development, programming

Pitfall of C array

CODE int main() { int my_array[4] = {11,12,13,14}; int next = 15; printf(“\nSurprise = %d”, my_array[4]); } What should it print? Well, although illegal, the above code does legal things. The array “my_array” has four integers allocated on the stack. The next integer “next” is allocated adjacent to the stack memory. So the address of […]

Read more
c language, development

Unfolding 2-D array in C

Last weekend my friends and I had a discussion on 2-D array in C. Surprisingly it went long as everyone had some points and knowledge to share 🙂 Finally we could gather some important information and understood this pearl of C better. I’ll clear this idea with C code snippets. // Declare an arrayint arr[2][3]= […]

Read more